From the course: Node.js: Web Servers, Tests, and Deployment

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Handling POST requests

Handling POST requests

- [Instructor] So if we fill out this form and click add term, we're going to notice that there is another error. So it's saying that it failed to load a resource and that we are failing to fetch. So let's take a look at the request with the Chrome browser tools here. If we go to the network tab, we're seeing that we're failing to load a resource. Remember that these HTTP requests are readable stream, so instead of handling the data ourselves, we can use an NPM called the body parser here to do the heavy lifting. So let's install body parser and we're going to add a post route to our application. So we're going to say, import body parser from body parser and then we'll import fs from fs. Once we've done this, we can call app.post and we're posting this to the /dictionary route. And here, we're going to use, as the second argument to post, body parser. There's a function called .json that's going to parse…

Contents