Follow these simple steps to learn how to create a login form using Node.js and MongoDB. Login form allows users to login to the website after they have created their account using the signup form.
Installation of modules:
$ npm install ejs
$ npm install express --save
Express is a module framework for Node that you can use for applications.
$ npm install mongoose
Mongoose is an Object Data Modeling (ODM) library for MongoDB and Node.js. It manages relationships between data, provides schema validation, and is used to translate between objects in code and the representation of those objects in MongoDB.
$ npm install body-parser --save
Body-parser allows express to read the body and then parse that into a JSON object that we can understand.
npm install express-session --save
Express.js uses a cookie to store a session id.
npm install passport passport-local --save npm install passport-local-mongoose --save
Passport is authentication middleware for Node. js. Extremely flexible and modular, Passport can be unobtrusively dropped in to any Express-based web application. A comprehensive set of strategies support authentication using a username and password, Facebook, Twitter, and more.
Steps to run the program:
- The project structure will look like this:
And the content of views directory will look like this:
Rest files will be the created after you run
npm initfor initialiasing
- Run index.js file using below command:
OR If you don’t have
nodemoninstalled you can run:
- Now go to your browser and type the following URL:
- First you will need to signup then only you can login into the app.
- Now you have successfully signup, Now this is login form as shown below:
This login form will take you to the Secret page as shown below:
So this is how you can create login form using Node.js and MongoDB.
- Signup Form Using Nodejs and MongoDB
- How to add a Login Form to an Image using HTML and CSS ?
- Nodejs - Connect MongoDB with Node app using MongooseJS
- HTML | Responsive Modal Login Form
- Nodejs | Automatic restart NodeJs server with nodemon
- How to implement Google Login in your Web app with Firebase ?
- How to implement Facebook login in your Web app with Firebase ?
- How to create admin login page using PHP ?
- Automated Login For Captive Portals in Linux
- Design a form component which takes input from its user and displays a form
- Nodejs | DNS
- Nodejs | DNS | setServers()
- Nodejs | Jimp
- Web-Socket in NodeJS
- Nodejs | GM randomThreshold() Function
- Nodejs | GM emboss() Function
- Nodejs | GM spread() Function
- Nodejs | GM despeckle() Function
- Nodejs | GM operator() 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 firstname.lastname@example.org. 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.