Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Node.js HttpRequest
'use strict';
const http = require('http');
let url = (process.env.targetURL)?process.env.targetURL:'google.com';
const options = {
hostname: url
};
function HttpRequest() {
let startTime = new Date();
let req = http.request(options, (res) => {
console.log(`STATUS: ${res.statusCode}`);
res.setEncoding('utf8');
res.on('data', (chunk) => {
});
res.on('end', () => {
let endTime = new Date();
let spendTime = (endTime.getTime() - startTime.getTime());
console.log( `request_timestamp : ${startTime.getTime()}, status : ${res.statusCode} - ${spendTime} ms` );
})
});
req.on('error', (e) => {
console.log(`problem with request: ${e.message}`);
});
req.end();
}
let testInterval = setInterval(HttpRequest, 1000);
@totuworld

This comment has been minimized.

Copy link
Owner Author

commented Apr 25, 2016

실행시 환경변수로 targetURL을 지정하지 않는다면 google.com으로 요청을 보낸다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.