Handling POST Requests

suggest change

Express handles GET with app.get and POST with app.post.

The body is not parsed until middleware does it. The body-parser package parses JSON and URL-encoded bodies into req.body. Express 4.16 and later includes the same parsers as express.json() and express.urlencoded().

var bodyParser = require('body-parser');

const express = require('express');

const app = express();

// Parses the body for POST, PUT, DELETE, etc.
app.use(bodyParser.json());

app.use(bodyParser.urlencoded({ extended: true }));

app.post('/post-data-here', function(req, res, next){

    console.log(req.body); // req.body contains the parsed body of the request.
    res.end();
});

app.listen(8080, 'localhost');

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents