I am currently working on a node.js web service which utilizes Express.js and Mongoose. Recently, I figured I would try my hand at CoffeeScript, as I have heard that there are some benefits to be had. However, I have noticed something a little unsettling, and I was curious if someone could clarify.
Here is one of my routes in plain javascript:
router.post('/get/:id', decorators.isManager, function(req, res) {
Group.findById(req.params.id, function(err, grp) {
if(err) res.status(500).end();
if(grp == null) res.status(500).send('The group could not be found');
res.send(grp);
});
});
However, with the following (nearly equivalent coffeescript):
router.post '/get/:id', decorators.isManager, (req, res) ->
Group.findById req.params.id, (err, grp) ->
res.status(500).end() if err
res.status(500).send 'The group could not be found' if not grp?
res.send grp
Re-compiling this to javascript returns the following:
router.post('/get/:id', decorators.isManager, function(req, res) {
return Group.findById(req.params.id, function(err, grp) {
if(err) res.status(500).end();
if(grp == null) res.status(500).send('The group could not be found');
return res.send(grp);
});
});
Will those extra returns effect the performance of my application, does it alter the way it works? I tested it, it seems to be the same response time however I am not sure the impact this will have on multiple nested queries. Thank you!