nodejs express read POST requests 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: 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);