简体   繁体   中英

Post Method does not get to the end point while using Express/Node.js

It is a simple code for sending a post request to a server but when I hit the end point it shows [Cannot get / "endpoint"] . However, when I send a get request, server responds with message "Ok". Please help me out here that what I am missing.

import express from 'express'
import bodyParser from 'body-parser'

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

app.post('/post', (req, res) => {
    console.log('Got body:', req.body);
    res.sendStatus(200);
});

app.listen(8080, () => console.log(`Started server at http://localhost:8080!`));`

Below is my Packago.json file.

在此处输入图像描述

The message I receive while hitting the endpoint is shown below

. 在此处输入图像描述

When we open a URL on a browser, that is a GET request and we want to read data. As far as POST request is concerned we have to use an API platform such as Postman to make a POST request as we submit our data to the server. That's it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM