Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js: Get Response Time

How can I know the response time of a URL?

I'm using http.get() to make an HTTP GET request.

like image 544
donald Avatar asked Feb 19 '11 16:02

donald


1 Answers

There's no builtin function or value to get the response time.

But you can easily get the value yourself.

var http = require('http');
var start = new Date();
http.get({host: 'google.com', port: 80}, function(res) {
    console.log('Request took:', new Date() - start, 'ms');
});

EDIT

Since V8 also supports the new ES5 Date.now(), using that instead of new Date() would be a little bit cleaner.

like image 163
Ivo Wetzel Avatar answered Sep 29 '22 11:09

Ivo Wetzel