I’m a junior developer I got new task to create three APIs GET,POST and DELETE using express application generator. I installed the npm install -g express-generator $ express
Post command should be something like this
"subscriberName": "Sunil",
"subsStartDate": "2023-01-01T1:30:13.123Z",
"subsEndDate": "2023-12-31T23:30:00.143Z"
}```
Response should be
```{
"subscriptionId : "0a1364a6-b59e-465d-9c70-1cf2b384e1c2"
"subscriberName": "Sunil",
"subsStartDate": "2023-01-01T1:30:13.123Z",
"subsEndDate": "2023-12-31T23:30:00.143Z",
"status" : "pending"
}```
so, I tried writing the code in Routes --> index.js
var express = require(‘express’);
var router = express.Router();
const uuid = require(‘uuid’);
router.post(‘/’, function(req, res, next) {
const id = uuid.v4();
const status = “pre”;
const message = {
id,
subsName: req.body.text,
subsStartDate: req.body.date(),
subsEndDate:req.body.date()
};
messages[id] = message;
return res.send(message);
});
});“`
I’m getting req.body.date is not a function
. Can someone please help?
Bharath Reddy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.