I am using the MEAN JS framework to create an app. My purpose is to detect a query parameter at the time of website load, and then set certain parameters for the app.
My server.js :
exports = module.exports = app;
Server controller
exports.index = function(req, res) {
console.log('URL is ' + req.url);
console.log('Path is ' + req.path);
var param1 = req.query.param1;
console.log('Parameter : ' + param1);
console.dir(req.query);
res.render('index', {
request: req,
myparam : param1 //Setting my custom parameter
});
};
URL accessed :
http://localhost:3000/#!/?param1=test
Output :
URL is /
Path is /
Parameter : undefined
{}
The query parameter is not being detected at all. Can someone please explain why this could be happening. I know Express ignores parameters while routing, but does it strip the url as well?
EDIT :
It was the angular fragment url which was causing the error. Once I made the URLs normal, Express detected all query parameters using the above method.
EDIT 2 :
Detailed answer here