libcurl bindings for node
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
deps fix(win-deps): windows build not working because of old libssh version Aug 11, 2018
examples feat(examples): add progress callback on simple request easy Aug 12, 2018
lib Merge pull request #143 from koskokos2/patch-4 Aug 17, 2018
scripts refactor(general): change code style to be more readable Feb 14, 2018
src fix: errors thrown inside callbacks are correctly handled Sep 14, 2018
test chore: decrease timeout between sends on progress test Sep 14, 2018
tools refactor: add a callback to brute force leak test Aug 12, 2018
.bithoundrc Added hints to v8 about memory allocations May 18, 2016
.codeclimate.yml Remove requiresafe from code analysis. Jan 7, 2016
.eslintignore refactor(general): change code style to be more readable Feb 14, 2018
.eslintrc refactor(general): change code style to be more readable Feb 14, 2018
.gitignore ignore .vscode folder Aug 12, 2018
.gitmodules Updated Windows deps, and added support for CURLOPT_HEADEROPT and CUR… Apr 15, 2015
.npmignore ignore .vscode folder on npmignore Aug 12, 2018
.prettierignore refactor(general): change code style to be more readable Feb 14, 2018
.travis.yml fix #43 mac libs should be linked against @rpath (#145) Aug 25, 2018
CHANGELOG.md docs: add new changelog entries Sep 14, 2018
LIBCURL_VERSION_WIN_DEPS fix(win-deps): windows build not working because of old libssh version Aug 11, 2018
LICENSE-MIT Small code style fixes. Updated copyright notice year. [skip ci] May 16, 2016
README.md chore(readme): improve readme May 4, 2018
api.md Updated dependencies. Jan 23, 2017
appveyor.yml Add Node 10 Jun 8, 2018
binding.gyp fix #43 mac libs should be linked against @rpath (#145) Aug 25, 2018
commitlint.config.js refactor(general): change code style to be more readable Feb 14, 2018
index.js refactor(general): change code style to be more readable Feb 14, 2018
jsdoc.json Removed old jsdoc template, regenerated api docs. Feb 22, 2016
package.json 2.0.0-alpha.0 Aug 25, 2018
yarn.lock feat: bump all the things Aug 12, 2018

README.md

node-libcurl

NPM version node license

Travis CI Status AppVeyor CI Status Code Quality Dependencies

Libcurl bindings for Node.js. Based on the work from jiangmiao/node-curl.

Quick Start

Install

npm i node-libcurl --save or yarn add node-libcurl

Simple Request

var Curl = require('node-libcurl').Curl;

var curl = new Curl();

curl.setOpt('URL', 'www.google.com');
curl.setOpt('FOLLOWLOCATION', true);

curl.on('end', function(statusCode, body, headers) {

    console.info(statusCode);
    console.info('---');
    console.info(body.length);
    console.info('---');
    console.info(this.getInfo( 'TOTAL_TIME'));

    this.close();
});

curl.on('error', curl.close.bind(curl));
curl.perform();

MultiPart Upload / HttpPost libcurl Option

var Curl = require('node-libcurl').Curl;

var curl = new Curl(),
    close = curl.close.bind(curl);

curl.setOpt(curl.option.URL, '127.0.0.1/upload.php');
curl.setOpt(curl.option.HTTPPOST, [
    { name: 'input-name', file: '/file/path', type: 'text/html' },
    { name: 'input-name2', contents: 'field-contents' }
]);

curl.on('end', close);
curl.on('error', close);

For more examples check the examples folder.

API

Check the API Docs

Almost all CURL options are supported, if you pass one that is not, an error will be thrown.

Detailed Installation

The latest version of this package has prebuilt binaries (thanks to node-pre-gyp) available for the latest two (2) versions of Node.js on Active LTS (or Maintenance LTS, see https://github.com/nodejs/Release) and for the following platforms:

  • Linux 64 bits
  • Mac OS X 64 bits
  • Windows 32 and 64 bits

Just running npm install node-libcurl should install a prebuilt binary and no compilation will be needed.

If there is no prebuilt binary available that matches your system, or if the installation fails, then you will need an environment capable of compilling nodejs addons, which means python 2.7 installed and an updated C++ compiler able to compile C++11.

If you don't want to use a prebuilt binary you can pass --build-from-source to the arguments list.

Linux

The only compiler supported on linux is gcc >=4.8, also you need to have the libcurl development files available, if you are running debian for example, you must install the libcurl4-openssl-dev package.

If you don't want to use the libcurl version shipped with your system, since it's probably very old (debian 7 uses libcurl 7.26 which is more than 3 years old, and had more than 1000 bugfixes already), you can install libcurl from source, for the addon to use that libcurl version intead, you need to make sure that:

  1. curl-config tool is in the PATH,
  2. You have to setup LDFLAGS so that it poins to the correct directory where the curl lib files are:
export LDFLAGS="-Wl,-rpath,${LIBCURL_PREFIX}/lib";

OS X

You need to have installed OS X >=10.8 and xcode >=4.5

Windows

If installing using a prebuilt binary you only need to have the visual c++ 2015 runtime library. If building from source, you need to have Python 2.7 and Visual Studio >= 2015, you can get all that by running:

npm install --global --production windows-build-tools

Currently there is no support to use other libcurl version than the one provided by the curl-for-windows submodule.

nw.js (aka node-webkit)

From nw.js documentation:

Starting from 0.13.0, native modules built by node-gyp or npm in upstream can be supported.

In Linux and OSX you can just load the native module directly. In windows you’ll need to replace the file %APPDATA%\npm\node_modules\node-gyp\src\win_delay_load_hook.c with the one at https://github.com/nwjs/nw.js/blob/nw13/tools/win_delay_load_hook.c

http://docs.nwjs.io/en/latest/For%20Users/Advanced/Use%20Native%20Node%20Modules/

Since we require node-gyp as direct dependency, you probably will need to change that file directly in the node-gyp inside the node_modules folder of your project.

electron (aka atom-shell)

Currently there are no prebuilt binaries for electron, to install node-libcurl, do the following:

npm install node-libcurl --runtime=electron --target=1.0.2 --disturl=https://atom.io/download/atom-shell --arch=x64 --save

--target says you want to build for the electron version 0.34.1.

--arch says the module should be built for 64bit.


You can put those args in a .npmrc file, like so:

runtime = electron
target = 1.0.2
target_arch = x64
dist_url = https://atom.io/download/atom-shell

Contributing

We are using yarn on this project.

If on Windows, run:

$ node tools/update-deps.js

Install the node modules:

$ yarn install

Build node-libcurl:

$ yarn pregyp rebuild