Working with body-parser - Create a Newsletter Signup Form with Node.js - Ep. 5

Released on November 2nd 2016
Length: 07:56

Learn how to grab input fields’ values with jQuery, send them off to a node server, and then parse them into a readable format with body-parser. When a POST request is sent to our server from an HTML form, our request object will contain a gigantic block of data which is lengthy and hard to read. Rather than being forced to pick and choose our data through this massive object, we can make use of the body-parser package to parse our form’s input values into a clean, succinct JSON object. If you’re familiar with PHP, you can think of this as creating your own $_POST variable. You just need to set it up yourself since node doesn’t come with the functionality out of the box. The body-parser package comes packaged with projects scaffolded by the Express command line interface (CLI), so there’s a very good chance you’ll use it more than once in the future. Enjoy everyone. Timeline: 0:46 - A visualization of what we’ll be implementing 1:19 - Grabbing the form data using jQuery 3:10 - Trying to grab our data without body-parser 4:09 - Implementing body-parser 6:04 - Why are there two body-parser use functions? 7:13 - How our post request looks with body-parser Resources: https://www.quora.com/What-exactly-does-body-parser-do-with-express-js-and-why-do-I-need-it https://github.com/expressjs/body-parser https://expressjs.com/en/guide/using-middleware.html https://expressjs.com/en/starter/static-files.html Beatz: Immortal Beats - Oh Wee - Creative Commons DK 64 - DK Gangsta Rap For updates on the progress of chriscourses.com and future videos, join the Chris Courses mailing list at http://chriscourses.com. Support Chris Courses Through Patreon: -------------------------------------- https://www.patreon.com/chriscourses Chris Courses Social: --------------------- Twitter: https://twitter.com/chriscourses Facebook: https://www.facebook.com/chriscourses Instagram: https://www.instagram.com/chriscourses Christopher Lis Social: ----------------------- Twitter: https://twitter.com/christopher4lis CodePen: http://codepen.io/christopher4lis