express req body json code example
Example 1: express req get json
const express = require('express');
const app = express();
app.use(express.json());
app.post('*', (req, res) => {
req.body;
});
const port = 3000;
app.listen(port, () => console.log(`Listening on port ${port}.`));
Example 2: express json body
$ npm install body-parser
Example 3: express json body
var bodyParser = require('body-parser')
Example 4: expressjs req.body.parameters
app.get('/user/:id', (req, res) => {
console.log(req.params.id)
})
or
app.get('/user/:user_id', (req, res) => {
console.log(req.params.user_id)
})