I am using Expressjs version 4.I am getting \'undefined\' on req.param. Here is my example : app.js
var express = require(\'express\');
var bodyParser = req
For anyone experiencing similar issues make sure to use params instead of param.
// Correct way
req.params.ID
// Wrong way
req.param.ID
req.params
Refers to the variables in your route path.
app.get("/posts/:id", ...
// => req.params.id
Post data can be referenced through req.body
app.post("/posts", ...
// => req.body.email
This assumes you are using the bodyParser
middleware.
And then there is req.query
, for those ?query=strings
.
You can use req.param()
for either of the 3 above. The look up order is params
, body
, query
.
param is a function, not an object. So you need to use req.param('email');
Two types are parameter are present
1. query (req.query.('name defined in route'));
2. path (req.params.('name defined in route));