needle
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
iconv-lite | 0.6.3 | 186.2 kB | MIT | prod | |
sax | 1.3.0 | 14.99 kB | ISC | prod |
Needle is a streamlined and efficient HTTP client for Node.js. This popular npm package is celebrated for its simplicity and lean structure, making it an ideal utility for rapid HTTP requests in Node.js. The package supports HTTP and HTTPS requests, various forms of authentication, multipart form-data, and automatic XML & JSON parsing among other advanced features. Its unique selling feature is its effectiveness in managing both simple and complex HTTP requests, including interaction with APIs and streaming of data.
To utilize Needle in a Node.js environment, users need to install the package and then include it within the code. The package can be installed via npm using the following command:
$ npm install needle
After successfully installing the package, it can be implemented in your application in the following ways:
For a basic GET request:
var needle = require('needle');
needle.get('http://www.google.com', function(error, response) {
if (!error && response.statusCode == 200)
console.log(response.body);
});
For a POST request with callbacks:
var data = {
file: '/home/johnlennon/walrus.png',
content_type: 'image/png'
};
needle.post('https://my.server.com/foo', data, { multipart: true })
.on('readable', function() { /* eat your chunks */ })
.on('done', function(err) {
console.log('Ready-o!');
});
And for a PUT request with promises:
needle('put', 'https://hacking.the.gibson/login', { password: 'god' }, { json: true })
.then(function(response) {
return doSomethingWith(response);
})
.catch(function(err) {
console.log('Call the locksmith!');
});
The comprehensive documentation for Needle is hosted on the github repository. The documentation provides detailed information about the package, its usage, examples, and options for various types of HTTP requests. It also includes information about handling responses, setting default options, testing, and the various event emissions that Needle supports.