11 - Registration of New Users - Advanced Node and Express - freeCodeCamp
Channel: Ganesh H
Date: 05/08/2020

To create a registration form, in the POST route, we should create the user's document in the database if it doesn't exist, and then authenticate them using their new details.

Link to Challenge : https://www.freecodecamp.org/learn/quality-assurance/advanced-node-and-express/registration-of-new-users
Written Guide: https://www.notion.so/ganeshh123/Registration-of-New-Users-95c5dde654c44bc0b84596b0ded5c59a
Full Playlist for this course : https://www.youtube.com/playlist?list=PLhGp6N0DI_1RL9djhgSH65pZhJ6xSyKX8
All Writen Guides for this course : https://www.notion.so/ganeshh123/ccf6039186334f83a54c1c9216f30e3c
All My Tutorials can be found at : https://www.notion.so/Tutorials-Ganesh-H-293ea420d34a464f9a1907e0405b5f26

00:00 - Introduction
00:16 - Registration Form
01:08 - POST Route
01:25 - 3 Steps to Registering a User
01:44 - Getting Form Data - bodyParser.urlEncoded()
Returns middleware that only parses urlencoded bodies and only looks at requests where the Content-Type header matches the type option. A new body object containing the parsed data is populated on the request object after the middleware (i.e. req.body). 
https://github.com/expressjs/body-parser#bodyparserurlencodedoptions
02:18 - Middleware for Database Work
02:38 - Check if User Already Exists -  db.collection.findOne()
Returns one document that satisfies the specified query criteria on the collection or view. If multiple documents satisfy the query, this method returns the first document according to the natural order which reflects the order of documents on the disk.
https://docs.mongodb.com/manual/reference/method/db.collection.findOne/
04:34 - Creating a User Document in the Database - db.collection.insertOne()
Inserts a single document into MongoDB. If documents passed in do not contain the _id field,
one will be added to each of the documents missing it by the driver, mutating the document.
http://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#insertOne
06:40 - Logging in the New User - passport.authenticate()
This function returns a middleware which runs the strategies. If one of the strategies succeeds, this will set req.user. If you pass no options or callback, and all strategies fail, this will write a 401 to the response. 
https://github.com/jwalton/passport-api-docs#passportauthenticatestrategyname-options-callback
07:32 - Redirecting the User to their Profile
08:40 - Testing the Registration
10:30 - Challenge Solution
16:06 - Explanation of Solution

-————————————————————————————————————-
Node.js is an open-source, cross-platform, JavaScript runtime environment that executes JavaScript code outside a web browser. Node.js lets developers use JavaScript to write command line tools and for server-side scripting—running scripts server-side to produce dynamic web page content before the page is sent to the user's web browser. 

Express.js, or simply Express, is a web application framework for Node.js. It is designed for building web applications and APIs. It has been called the de facto standard server framework for Node.js. Express runs between the server created by Node.js and the frontend pages of a web application. Express also handles an application's routing.

freeCodeCamp (also referred to as “Free Code Camp”) is a non-profit organization that consists of an interactive learning web platform, an online community forum, chat rooms, online publications and local organizations that intend to make learning web development accessible to anyone. Beginning with tutorials that introduce students to HTML, CSS and JavaScript, students progress to project assignments that they complete either alone or in pairs. Upon completion of all project tasks, students are partnered with other nonprofits to build web applications, giving the students practical development experience.

freeCodeCamp (also referred to as “Free Code Camp”) is a non-profit organization that consists of an interactive learning web platform, an online community forum, chat rooms, online publications and local organizations that intend to make learning web development accessible to anyone. Beginning with tutorials that introduce students to HTML, CSS and JavaScript, students progress to project assignments that they complete either alone or in pairs. Upon completion of all project tasks, students are partnered with other nonprofits to build web applications, giving the students practical development experience.

Thanks for Watching!