NodeJs Request.Get Example with Error Handling

Posted on September 6, 2019 at 9:53 am

Here is an example of using NodeJs “request” library with error handling:

var dateformat = require('dateformat');
var request = require('request');
request.get('',function(err, res, body)
    if(err) console.error('[Request.Get] %s Error:', dateformat(new Date(), "yyyy-mm-dd h:MM:ss"), err.message);
    console.log('[Request.Get] %s StatusCode:', dateformat(new Date(), "yyyy-mm-dd h:MM:ss"), res.statusCode);

It should output something like this:

[Request.Get] 2019-09-06 9:45:07 StatusCode: 200

Receive updates via email

Other Posts

Updated Posts