Skip to Main Content

Kelbe Fox ID226

Advanced Web Scripting

POST Exercise

POST is a method that can fetch data. Thanks to Express, we can use a POST request to fetch data in Node as well. How it works is that your data is attached to the request object when it is posted. In the response, we can set up code that can extract the information from the request. This is often done by using the body-parser module as middleware.

In this exercise, have an html page that accepts input from a user. We also made a script called server.js that creates a local server for the page, and uses Express and POST to manipulate that input and pass it to another page. We prevent invalid data from causing issues with our validator.js file. The code below explains the process in further detail.

Once we run server.js in the Console, we can visit the HTML page in a browser at localhost:8080, and test the app.