Node.js ExpressJS App Must Have
/*
This is a super simple way to get at URL query values without having
to require and parse each time a value is needed. This will run every
time the ExpressJS server gets a request. It parses and places the results
into the req variable. as urlParams.
This will DRY out a route call without changing the expected behavior.
*/
app.use(function(req, res, next) {
var url = require('url');
var queryURL = url.parse(req.url, true);
req.urlparams = queryURL.query;
next();
});
/*
Usage:
var myID = req.urlparams.myID;
*/
Written by Stephan Smith
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Nodejs
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#