Answers for "how to post data to api in node js server req.body"

4

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!`));
Posted by: Guest on May-17-2020
6

How to access the request body when POSTing using Node.js and Express

const express = require('express');

const app = express();

app.use(express.json({extended: false})); //This is the line that you want to add

app.post('/postroute', (req, res) => {
    console.log('body :', req.body);
    res.sendStatus(200);
});
Posted by: Guest on July-18-2020

Code answers related to "how to post data to api in node js server req.body"

Code answers related to "Javascript"

Browse Popular Code Answers by Language