(Express) Hello I'm trying to make a very simple post request to localhost via postman but it gets stuck on sending. To be clear, the first time I've tried it, it worked, but after adding a mongoose implementation it didn't work anymore even after menting the changes.
const router = require('express').Router();
router.post('/', (req, res) => {
console.log("Got here");
res.send("ciao");
});
app.listen(port, () => {
console.log("Server running on port: " + port);
});
If it was working correctly I'd see "Got here"
Postman app
I'm using postman 8.0.2 desktop app for mac, i've tried to remove and install again.
EDIT I've tried creating another project and it works again i'll investigate on what i did wrong and maybe add a ment.
(Express) Hello I'm trying to make a very simple post request to localhost via postman but it gets stuck on sending. To be clear, the first time I've tried it, it worked, but after adding a mongoose implementation it didn't work anymore even after menting the changes.
const router = require('express').Router();
router.post('/', (req, res) => {
console.log("Got here");
res.send("ciao");
});
app.listen(port, () => {
console.log("Server running on port: " + port);
});
If it was working correctly I'd see "Got here"
Postman app
I'm using postman 8.0.2 desktop app for mac, i've tried to remove and install again.
EDIT I've tried creating another project and it works again i'll investigate on what i did wrong and maybe add a ment.
Share Improve this question edited Jan 26, 2021 at 8:20 Aziza Kasenova 1,5692 gold badges13 silver badges24 bronze badges asked Jan 25, 2021 at 18:54 Federico TarascioFederico Tarascio 331 gold badge1 silver badge5 bronze badges 2- @Adam nope, mongo connection is mented, even if it didn't it was ok no problems with that – Federico Tarascio Commented Jan 25, 2021 at 19:00
- Try this:app.use(express.json()); app.use(express.urlencoded({extended: true})) – arevilla009 Commented Jan 25, 2021 at 19:24
1 Answer
Reset to default 3add router as middleware to the express, below is your updated code
const router = require('express').Router();
router.post('/', (req, res) => {
console.log("Got here");
res.send("ciao");
});
app.use('/', router);
app.listen(port, () => {
console.log("Server running on port: " + port)
});