Code Snippet - How to Access Query String at Node.js

2014/5/21 min read
bookmark this
Responsive image

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);