javascript - Node.js - pass variable between sessions -
say have code in node.js:
app.post('/stuff', function(req, res){ res.send('hello world'); }); app.route('*').all(function(req,res,next){ res.write('hello world'); }); there 2 routes here - 1 catch-all request server , other if post request route of /stuff sent.
is possible pass value local post request route?
intended program flow: initial request server goes through route (which has controls not illustrated ignore post requests) , connection left open, post request sent initial request , dealt app.post - can value found within closure of post passed initial request still open?
i trying avoid using global variables, , res.local has local scope. trying keep clean if can use native express or node.js better. obliged help.
then post request sent initial request
why don't pull out post function , call both handlers, way don't need send seperate request inside app.
var posthandler = function(req, res) { res.send('hello world'); // return whatever want calling function return somevalue; }; // set handler post. app.post('/stuff', posthandler); app.route('*').all(function(req,res,next){ // call function. var returnvalue = posthandler(req, res); res.write('hello world'); });
Comments
Post a Comment