I am new in nodeJS, I have created this application:
const express = require('express');
const app = express();
app.use (express.json());
app.post('api/hostels', (req, res) => {
const hostel = {
id : hostels.length + 1,
name: req.body.name
};
hostels.push(hostel);
res.send(hostel);
});
I send this body in the PostMan raw body (json)
{
"id": "4",
"name" : "new Request"
}
but I am getting this error:
<body>
<pre>Cannot POST /api/requests</pre>
</body>