http-sync is a compiled Node.js extension that provides syncronous http calls.
You must have libcurl installed in order to compile this extension.
On Ubuntu, you can run: sudo apt-get install libcurl4-openssl-dev
// example with default options
httpSync = require('http-sync');
var request = httpSync.request({
method: 'GET',
headers: {},
body: '',
protocol: 'http',
host: '127.0.0.1',
port: 80, //443 if protocol = https
path: '/'
});
var timedout = false;
req.setTimeout(10, function() {
console.log("Request Timedout!");
timedout = true;
});
var response = request.end();
if (!timedout) {
console.log(response);
console.log(response.body.toString());
}
node-gyp configure && node-gyp build
You will need:
- node.js source code
- v8 source code
- libcurl development package
Building:
node-waf configure && node-waf build
Run the test.js file:
node test.js