Rishabh Raghwendra
Rishabh Raghwendra

Reputation: 320

Why my app.get('/') is not getting request in express

I am new to backend development and learning express. I have the following code:

index.js:

const express = require('express');
const app = express();

app.get('/',(req,res)=>{
    console.log("hitting request");
})
app.listen(3001,()=>console.log("Mock server listening at 3001"));

But when I am hitting http://localhost:3001/ in postman nothing is printed on console.

May anyone tell me why I am getting this issue? I am also using nodemon as dev dependency.

package.json:

{
  "name": "mock-server",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "scripts": {
    "dev": "nodemon index.js"
  },
  "dependencies": {
    "bignumber.js": "^9.1.0",
    "express": "^4.18.1"
  },
  "devDependencies": {
    "nodemon": "^2.0.19"
  }
}

Upvotes: 0

Views: 48

Answers (1)

Med Hmema
Med Hmema

Reputation: 21

You used

console.log("hitting request");

Means you will get the "hitting request" message on the console you used (CMD for example). If you want to get it in postman you have to use :

res.send("hitting request");

Upvotes: 1

Related Questions