Cannot POST /<name of route>


<form action="/update" method="post" id="form3">
   <input id="desc" type="text" name="desc" placeholder="description">


app.put('/update', function (req, res) {
   const desc= req.body.desc;

I created this as a test to make sure I can get app.put() to work before I start with the database update.
But I get this error, even the console.log() doesn’t work:

Cannot POST /update

I have an and an app.get() working.

I am not sure if I understand… are you testing the post or put?
Because the route you have defined here is a .put route, and you are sending a post request. In index.html, you should change the method to ‘put’ in your form if you want to reach the app.put endpoint.

When I change the form method to PUT I get the error: Cannot GET /update

Oh, I just realized… you can only use get and post within a html form tag. Get is the default, so if it doesn’t recognize the method, it will use get.

You will need to send your put request with javascript, using jQuery’s ajax requests, or XMLHttpRequest

If you want to quickly test that your endpoint is working, you can also use postman.

1 Like