Is there a curl in NodeJs?

4

Well this is what I needed for some function that would serve as a "curl" for use in nodejs.

Is there any function, which does the equivalent of curl in php?

Thank you.

    
asked by anonymous 25.03.2017 / 03:12

1 answer

3

See the documentation for a complete example and how to use the HTTP module: link

You also have this example

var http = require("http");

var options = {
  host: 'www.google.com',
  port: 80,
  path: '/upload',
  method: 'POST'
};

var req = http.request(options, function(res) {
  console.log('STATUS: ' + res.statusCode);
  console.log('HEADERS: ' + JSON.stringify(res.headers));
  res.setEncoding('utf8');
  res.on('data', function (chunk) {
    console.log('BODY: ' + chunk);
  });
});

req.on('error', function(e) {
  console.log('problem with request: ' + e.message);
});

// write data to request body
req.write('data\n');
req.write('data\n');
req.end();

So yes, there is something equivalent.

    
25.03.2017 / 03:34