Home > Net >  Getting connot GET /create, while making POST request in Express.js
Getting connot GET /create, while making POST request in Express.js

Time:11-29

const express = require("express")
const app = express()
app.post("/create1",(req,resp)=>{
    console.log("server started")
    resp.send("done")
})

app.listen(3000)

I should get a

send

on the

 https:// localhost:3000/create,

i tried changing port number, but am getting same error

CodePudding user response:

This should go ahead and fix your problem.

app.get("/create",(req, res)=>{
    console.log("server started");
    res.send("done");
})

CodePudding user response:

There are 3 reasons for not getting the response.

  1. You named the route as create1 but you are hitting the API as create.
  2. You used https. It will be http
  3. You have created a POST (app.post(...) route but you are calling the route in GET method. So, use Postman tool, change the method to POST and hit the API.

So, The API would be : http://localhost:3000/create1 (Hit it in POST method from Postman)

  • Related