Node.js Express -
i have express server, , write like
for(p in params) app.get("/"+p,function (req, res) {res.send(p)});
now, params[0], request arrives, response params[n-1]
you can use anonimous function make copy of 'p' on each iteration.
var http = require('http'); var express = require('express'); var app = express(); var params = { 'a' : 1, 'b' : 2, 'c' : 3 }; (p in params) { (function (p) { app.get('/' + p, function (req, res) { res.send(p); }); })(p); } http.createserver(app).listen(1339, '0.0.0.0');
Comments
Post a Comment