Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make external HTTP requests with Node.js [closed]

Tags:

http

node.js

The question is fairly simple. I want to use a Node.js server as a proxy to log, authenticate, and forward HTTP queries to a backend HTTP server (PUT, GET, and DELETE requests).

What library should I use for that purpose? I'm afraid I can't find one.

like image 329
Pierre Avatar asked Nov 01 '11 13:11

Pierre


People also ask

Do Node.js servers block on HTTP requests?

Your code is non-blocking because it uses non-blocking I/O with the request() function. This means that node. js is free to service other requests while your series of http requests is being fetched.

How do I stop a Node.js request?

destroy() really works, uncomment it, and the response object will keep emitting events until it closes itself (at which point node will exit this script).


1 Answers

NodeJS supports http.request as a standard module: http://nodejs.org/docs/v0.4.11/api/http.html#http.request

var http = require('http');  var options = {   host: 'example.com',   port: 80,   path: '/foo.html' };  http.get(options, function(resp){   resp.on('data', function(chunk){     //do something with chunk   }); }).on("error", function(e){   console.log("Got error: " + e.message); }); 
like image 175
chovy Avatar answered Sep 29 '22 07:09

chovy