const data = {
employees: require("../data/employees.json"),
setEmployees: function (data) { this.employees = data; }
};
const getAllEmployeesData = (requestt, responsee) => {
responsee.json(data.employees)
}
const getSpecificEmployee = (req, res) => {
const employee = data.employees.find((emp) => { emp.id === parseInt(req.params.id);});
if (!employee) {
return res.status(400).json({ "message": `Employee ID ${req.params.id} not found` });
}
const filteredArray = data.employees.filter(emp => emp.id === parseInt(req.body.id));
data.setEmployees([...filteredArray])
res.json(data.employees);
}
in this line const employee = data.employees.find((emp) => { emp.id === parseInt(req.params.id);});
in above code employee is showing undefined but the conditional statement is returning true
and also no such error like MODULE NOT FOUND that means nothing is wrong while importing my employee.json
my employees.json file
[
{
“id”: 1,
“firstname”: “hello”,
“lastname”: “bye”
},
{
“id”: 2,
“firstname”: “you”,
“lastname”: “me”
}
]