two request sample
1. GET
app.get('/product:id',function(req,res){
});
here we passing id of product dynamically
2. POST
app.post('/add',function(req,res){
});
how to get request query string .
req.params get access of query string .
app.get('/product:id',function(req,res){
console.log(req.params.id)
});
for http://127.0.0.1:3000/product/124 , req.params.id give use 124
for the post value we need body parser
so import it by npm command
npm install body-parser
at code
first load body-parser module
var bodyParser = require('body-parser');
now use it
app.use(bodyParser());
now get post body
app.post('/add',function(req,res){
console.log(req.body.item);
});
where request.body.postParameterName
Middleware for handling multipart/form-data is multer .
3. all
The app.all() method is useful for mapping “global†logic for specific path prefixes or arbitrary matches
app.all('*', requireAuthentication);
it means it need to run requireAuthentication for all request .