get url query string at node.js

Posted in Node.js, on 5/3/2014

If you want to get the query string like following 

http://localhost:9000/api/myapi?id=1

at your node.js code, you can write this to get the id's value at the function you defined for you api.

var url = require('url');
var url_parts = url.parse(req.url, true);
console.info(url.parts.querystring.id);