Wednesday, 14 August 2013

Passing Extra Parameters in express - Node.JS

Passing Extra Parameters in express - Node.JS

I'm trying to remove the anonymous functions from my node application. For
instance:
app.post('/page-edit.json', function (req, res) {
db.get(req.body.page_id, function (err, doc) {
res.contentType('json');
res.send(doc);
});
});
So say I break out the inner function:
function innerMost(err, doc) {
res.contentType('json');
res.send(doc);
}
function outer(err, doc) {
db.get(req.body.page_id, innerMost);
}
app.post('/page-edit.json', outer);
The question is, how do I pass extra parameters, like 'res' into
'innerMost'? It's getting lost in the process.
If you want to see the source code (or even want to contribute to the open
source project!) you can see it here!

No comments:

Post a Comment