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

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -