Skip to content

Instantly share code, notes, and snippets.

Created Dec 14, 2011
What would you like to do?
Node.js turn querystring params into JSON
var http = require('http'),
url = require('url'),
util = require('util');
http.createServer( function (req, res) {
res.writeHead( 200, {'Content-Type': 'text/plain'} );
var qs = url.parse( req.url, true );
res.write( util.inspect( qs.query ) );
console.log('Server running at port 8000');

This comment has been minimized.

Copy link
Owner Author

@asabaylus asabaylus commented Dec 14, 2011

Turns this URL: http://localhost:8000/?id=123&a=apple&b=baby
Into this JSON: { id: '123', a: 'apple', b: 'baby' }


This comment has been minimized.

Copy link

@revskill10 revskill10 commented Nov 19, 2016

What about nested key, like auth[email] ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment