Parsing means accessing the data submitted by user with HTML form. When the form is submitted with the ‘GET’ method, data are appended in ‘query string’ and can access easily but when a form is submitted using the ‘POST’ method, it is somewhat difficult to get access over those data since they are encoded because of security purpose.
There exist a body-parser NPM method that makes it very easy to parse the data but if we try to implement this parsing method from scratch, there’s involve some steps.
- Install Express package
npm install express
- Starting express server(set app listener)
- create the route for ‘POST’ form submission and setting up middleware function call
app.post(path, middleware, callback)
- create middleware parsing function
- Excess the encoded form data aap.on() method.
- Convert the encoded data into string using decodeURIComponent() method.
- Create an object of user submitted data and assign it to req.body of request object.
Example 1: This example creating a login form.
- Login Form:
- Fetched login information:
Exapmle 2: This example creating a registration form.
- Registration Form:
- Fetched Registration data and printing it on console:
- Introduction to Xamarin | A Software for Mobile App Development and App Creation
- Deploying Your Web App using Azure App Service
- Progressive Web App - A Combination of Native and Web App
- Express.js | app.disable() Function
- Why Express ‘app’ and ‘server’ files kept separately ?
- Express.js | app.path() Function
- Express.js | app.set() Function
- Express.js | app.route() Function
- Express.js | app.post() Function
- Express.js | app.put() Function
- Express.js | app.listen() Function
- Express.js | app.METHOD() Function
- Express.js | app.param() Function
- Express.js | app.all() Function
- Express.js | app.render() Function
- Express.js | app.get() Request Function
- Express.js | app.get() Function
- Express.js | app.delete() Function
- Express.js | app.use() Function
- Express.js | app.enabled() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.