npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

convertapi

v1.15.0

Published

Official convertapi.com API client

Downloads

76,959

Readme

ConvertAPI Node.js Client

npm version Build Status License: MIT

Convert your files with our online file conversion API

The ConvertAPI helps in converting various file formats. Creating PDF and Images from various sources like Word, Excel, Powerpoint, images, web pages or raw HTML codes. Merge, Encrypt, Split, Repair and Decrypt PDF files and many other file manipulations. You can integrate it into your application in just a few minutes and use it easily.

Installation

npm install convertapi --save

Usage

The package needs to be configured with your account's secret key or token which is available at https://www.convertapi.com/a

Require it with the key's value:

var convertapi = require('convertapi')('your-api-secret-or-token');

Or using ES modules:

import ConvertAPI from 'convertapi';

const convertapi = new ConvertAPI('your-api-secret-or-token');

You can specify additional options, like proxy configuration and timeouts, when initializing the client:

var convertapi = require('convertapi')('your-api-secret-or-token', {
  conversionTimeout: 60,
  uploadTimeout: 60,
  downloadTimeout: 60,
  proxy: {
    host: '127.0.0.1',
    port: 9000,
    auth: {
      username: 'testuser',
      password: 'secret'
    }
  },
  keepAlive: true
});

If using ES module:

const convertapi = new ConvertAPI('your-api-secret-or-token', { conversionTimeout: 60 });

File conversion

Convert file to PDF example. All supported file formats and options can be found here.

convertapi.convert('pdf', { File: '/path/to/my_file.docx' })
  .then(function(result) {
    // get converted file url
    console.log("Converted file url: " + result.file.url);

    // save to file
    return result.file.save('/path/to/save/file.pdf');
  })
  .then(function(file) {
    console.log("File saved: " + file);
  })
  .catch(function(e) {
    console.error(e.toString());
  });

Other result operations:

// save all result files to folder
result.saveFiles('/path/to/save/files').then(function(files) {
  console.log("Files saved: " + files);
});

// get conversion cost
console.log("Conversion cost: " + result.conversionCost);

Convert file url

var resultPromise = convertapi.convert('pdf', { File: 'https://website/my_file.docx' });

Specifying from format

var resultPromise = convertapi.convert('pdf', { File: 'https://website/my_file' }, 'docx');

Additional conversion parameters

ConvertAPI accepts additional conversion parameters depending on selected formats. All conversion parameters and explanations can be found here.

var resultPromise = convertapi.convert(
  'pdf',
  {
    File: '/path/to/my_file.docx',
    PageRange: '1-10',
    PdfResolution: '150',
  }
);

User information

You can always check your conversion counts by fetching user information.

convertapi.getUser().then(function(info) {
  console.log("ConversionsTotal: " + info.ConversionsTotal);
  console.log("ConversionsConsumed: " + info.ConversionsConsumed);
});

Error handling

convertapi
  .convert('pdf', { File: 'https://website/my_file.docx' })
  .catch(function(e) {
    console.error(e.toString());
    console.debug(e.request);
    console.debug(e.response);
  });

Alternative domain

Set base_uri parameter to use other service domains. Dedicated to the region domain list.

var convertapi = require('../lib')(process.env.CONVERT_API_SECRET, { baseUri: 'https://eu-v2.convertapi.com/' });

More examples

Find more advanced examples in the examples/ folder.

Development Commands

  • npm run clean - Remove the lib/ directory
  • npm test - Run tests with linting and coverage results.
  • npm run test:only - Run tests without linting or coverage.
  • npm run test:watch - You can even re-run tests on file changes!
  • npm run test:prod - Run tests with minified code.
  • npm run test:examples - Test written examples on pure JS for better understanding module usage.
  • npm run lint - Run ESlint with airbnb-config
  • npm run cover - Get coverage report for your code.
  • npm run build - Babel will transpile ES6 => ES5 and minify the code.
  • npm run prepublish - Hook for npm. Do all the checks before publishing your module.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/ConvertAPI/convertapi-node. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

ConvertAPI Node.js Client is available as open source under the terms of the MIT License.