1

I am new to Express.js and I am using postman for api. When i execute the below code i get all the members from the object

// gets all members
app.get('/api/members', (req, res) => {
    res.json(members)
})

postman image for displaying all members

but when i try to access single member from the api using the following code i get the 404 error in postman

// get single member
app.get('/api/member/:id', (req, res) => {
    res.json(members.filter((member) => member.id === parseInt(req.params.id)))
})

postman error message for accessing single user

here is the full members object code which is converted to api

const members = [
    {
        id: 1,
        name: 'jack',
        email: 'jack@me.com',
        status: 'active'
    },
    {
        id: 2,
        name: 'sheldon',
        email: 'sheldon@me.com',
        status: 'inactive'
    },
    {
        id: 3,
        name: 'matt',
        email: 'matt@me.com',
        status: 'active'
    },
]

module.exports = members

Someone please explain what the error is...

1 Answers1

1

So your express route is set to '/api/member/:id' and you are sending request at '/api/members/1' end-point. Try removing 's' from your postman request's url. In simple words, try: '/api/member/1'