express body params code example
Example 1: How to parse POST requests with express nodejs
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.post('/post-test', (req, res) => {
console.log('Got body:', req.body);
res.sendStatus(200);
});
app.listen(8080, () => console.log(`Started server at http://localhost:8080!`));
Example 2: express receive post data
const { id } = req.body;
Example 3: node express post request json
var express = require('express');
var app = express();
app.use(express.json());
app.post('/', function(request, response){
let myJson = request.body;
let myValue = request.body.myKey;
response.send(myJson);
});
app.listen(3000);