Augustin
Augustin

Reputation: 15

How do I get the {{id}} from the url in express +Node.js

I'm trying to create a CRUD app using Node and express, i'm relatively new to it. I have an ideas page and an edit button on each idea. I keep on getting the error "Cannot GET /ideas/edit1/" when I click the edit button(this view exists by the way).

Here's the code I used to edit data in a form:

app.get('/ideas/edit/:id', (req, res) => {
    Idea.findOne({
            _ id: req.params.id
        })
        .then(idea => {
            res.render('ideas/edit1', {
                idea: idea
            });
        });

})

I have checked the express documentation and i'm pretty sure express uses the : to denote a variable in a route.

I'm wondering what else to do.

Upvotes: 0

Views: 1352

Answers (2)

Cybertech
Cybertech

Reputation: 8

Check your form, maybe you are not passing the id correctly.

Upvotes: 0

user12069108
user12069108

Reputation:

Instead of res.render('ideas/edit1' you should be using res.render('ideas/edit/1')

Upvotes: 1

Related Questions