node.js - how to find request parameters in 'nodejs' -


when sent request nodejs server,

how can find parameters sent in request query when request sent nodejs server.

req.param  req.params  req.query 

all giving undefined.

also when stringify req request gives error :

converting circular structure json 

how find query parameters.

you can use url module:

$ npm install url 

and this:

var http = require("http"); var url = require("url");  http.createserver(function(req, res) {    var parsedurl = url.parse(req.url, true); // true query object   var queryasobject = parsedurl.query;    console.log(json.stringify(queryasobject));    res.end(json.stringify(queryasobject));  }).listen(8080);  console.log("server listening on port 8080"); 

test in browser:

http://localhost:8080/?a=123&b=xxy 

for post requests can use bodyparser.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -