node.js - what is the best way to log errors in NodeJs when my NodeJs application calls/consumes another rest service? -


in few words, have nodejs application running in company dmz receives calls mobile , forward such calls other rest services running in server (websphere beyond our dmz layer).

i have been reading lot how nodejs behaves different java (i mean, default asynchronous nodejs behavior versus default java synchronous behavior). can imagine, bit new nodejs logs best practices.

it clear me rules of thumbs "don't use try/catch in asynchronous code". nevertheless, can't judge best idea approach code bellow neither if @ least doing acceptable solution bellow (see end of code).

to reveal bit more limitation, don't know judge if such peace of code asynchronous or synchronous. well, guess synchronous because didn't use call functions neither promises library.

by way, should use try/catch approach bellow or wrap in domain? if so, idea how high appreciated.

var app = express();  app.use(bodyparser.json()); app.use(bodyparser.urlencoded({   extended: true }));  var router = express.router();  var tokenroute = router.route('/token');  //bellow 1 of nodejs rest service receives call mobile , call forward spring application answer token tokenroute.post(function (req, res) {    var bilhetagem = {     cpf: req.body.username,     servico: 'login'   };    logstash.send(bilhetagem);    var dataauth = 'grant_type=' + req.body.grant_type +     '&username=' + req.body.username + '&password=' + req.body.password;    var auth = req.headers.authorization;    var args = {     data: dataauth,     headers: { "content-type": "application/x-www-form-urlencoded", 'authorization': auth }   };    var backend = ... here rest service our websphere beyond dmz layer    client.registermethod("postmethod", backend, "post");    //here relies main part of doubt. let's there predictable exception (eg. timeout). best aprroach here?   client.methods.postmethod(args, function (data, response) {      res.writehead(200, { "content-type": "application/json" });     var json = json.stringify({       tokenbackend: data     });     res.end(json);    });  });  app.use('/', router);  https.createserver(options, app).listen(config.get('node-porta'));   //here current solution , work wondering if realy doing practice on here. //ps. wrote below console.log focus on question logging in file , on process.on('uncaughtexception', function (err) {   console.log("process.on(uncaughtexception)",err.message); }); 


Comments