A simple Node.js authentication starter built with Express, Passport, MongoDB, Mongoose, EJS, and Bootstrap.
This project demonstrates:
- Local authentication with Passport
- User registration and login
- Password hashing with bcryptjs
- Protected dashboard route
- Flash messages for validation and auth feedback
- EJS views with a Bootstrap-powered UI
2.0.0
- Node.js 22 or newer recommended
- npm
- MongoDB Atlas or a local MongoDB database
npm installOpen config/keys.js and replace the placeholder MongoDB URI with your own local or Atlas connection string.
Example local URI:
const dbPassword = 'mongodb://127.0.0.1:27017/node_passport_login';
module.exports = {
mongoURI: dbPassword
};For MongoDB Atlas, use the connection string from your Atlas dashboard and make sure your database username, password, and network access settings are correct.
Do not commit real database credentials to GitHub.
npm startFor development with automatic restarts:
npm run devThen visit:
http://localhost:5000
GET /- welcome pageGET /users/register- register pagePOST /users/register- create a userGET /users/login- login pagePOST /users/login- authenticate a userGET /dashboard- protected dashboardGET /users/logout- logout
npm start
npm run devThis project uses current major versions of the main packages, including Express 5, EJS 5, Mongoose 9, Passport 0.7, and Bootstrap 5.