styler:
I'm trying to create a simple node server that on a GET request for the following paths, returns some static JSON:
/employees /employees/:id
I've created 2 GET requests, but my problem comes when trying to GET 1 Employee as the employees data doesn't exist, I've tried using a variable to store the data in /employees but this doesn't seem to work. Do I need to combine and check if an id exists?
let employees = []
app.get('/employees', (req, res) => { let data = generate(100) employees = data
console.log(req.body)
res.json({
"status": "success",
"data": data,
"message": []
}).end()
})
app.get('/employees/:id', (req, res) => {
let employee = _.find(employees, {"id": req.params.id}) //employees doesn't exist
res.json({
"status": "success",
"data": employee,
"message": []
}).end()
})
Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE