This is a simple login system built with Node.js. It uses express
for the server, ejs
as the view engine, and various authentication-related dependencies to handle user login and sessions.
NOTE: Database isn't setup. Login Credentials are stored in local storage
express
ejs
bcrypt
passport
passport-local
express-session
express-flash
dotenv
-
Clone the repository:
git clone https://github.com/your-username/nodejs-simple-login-system.git
-
Navigate to the project directory:
cd nodejs-simple-login-system
-
Install the dependencies:
npm install
-
Create a
.env
file in the root of the project and add your session secret:SESSION_SECRET=any_secret_key
-
Start the server:
npm start
-
Open your browser and navigate to:
http://localhost:3000
express
is a minimal and flexible Node.js web application framework. It provides a robust set of features to develop web and mobile applications.
- Usage in your code:
const express = require('express'); const app = express(); app.use(express.urlencoded({ extended: false }));
ejs
(Embedded JavaScript templates) is a simple templating language that lets you generate HTML markup with plain JavaScript.
- Usage in your code:
app.set('view engine', 'ejs');
bcrypt
is a library to help you hash passwords. It uses the bcrypt hashing function to securely hash user passwords before storing them in the database.
- Usage in your code:
const bcrypt = require('bcrypt'); const hashedPassword = await bcrypt.hash(password, 10);
passport
is authentication middleware for Node.js, while passport-local
is a Passport strategy for authenticating with a username and password.
- Usage in your code:
const passport = require('passport'); const LocalStrategy = require('passport-local').Strategy; passport.use(new LocalStrategy( function(username, password, done) { // Authentication logic here } ));
express-session
is a middleware to handle sessions in your application. It stores session data on the server and gives the client a session ID to identify their session.
- Usage in your code:
const session = require('express-session'); app.use(session({ secret: process.env.SESSION_SECRET, resave: false, saveUninitialized: false }));
express-flash
is a flash message middleware for Express. It provides a way to display messages to the user after a redirect.
- Usage in your code:
const flash = require('express-flash'); app.use(flash());
dotenv
is a module that loads environment variables from a .env
file into process.env
.
- Usage in your code:
require('dotenv').config();
This simple login system provides the basic structure for handling user authentication in a Node.js application. By leveraging the above-mentioned dependencies, you can easily extend and customize it to fit your specific needs.
Feel free to fork this project, make improvements, and send a pull request. Any contributions are welcome!
This project is licensed under the MIT License. See the LICENSE file for more details.