User Authentication with ExpressJS, Mongoose, JSON Web Token, and MongoDB
This project provides a simple user authentication system with a login and sign-up page. It utilizes ExpressJS as the backend framework, Mongoose as the ODM (Object Data Modeling) library for MongoDB, the JSON Web Token (jsonwebtoken) library for secure user authentication, EJS (Embedded JavaScript) for rendering dynamic views on the frontend, and MongoDB as the database for storing user information.
- User Registration: Allows users to sign up with a unique username and password.
- User Authentication: Validates user credentials during login using JSON Web Tokens.
- Secure Password Storage: Safely stores user passwords using encryption techniques provided by Mongoose.
- MongoDB Integration: Utilizes MongoDB as the database for storing user information.
-
Clone the repository:
git clone https://github.com/abhishekpaturkar/authentication-jsonwebtoken.git
-
Navigate to the project directory:
cd Auth
-
Install dependencies:
npm install
-
Set up MongoDB:
- Create a MongoDB database.
- Update the MongoDB connection string in the
db/db.js
file.
exports.connectMongoose = () => {
mongoose
.connect("MongoDBURL")
.then((e) => console.log(`Conneccted to mongoDB: ${e.connection.host}`))
.catch((e) => console.log(e));
};
-
Start the server:
npm run dev
-
Open your browser and go to http://localhost:3000 to access the application.
- Add
config.js
file in main folder and add theKEY
for your jsonwebtoken
// config.js
module.exports = {
// Other configurations...
KEY: 'YOUR-KEY',
};
- Open the application in your browser.
- Register a new user using the sign-up page.
- Log in with the registered user credentials.
- Explore and integrate the authentication system into your own projects.
- ExpressJS: Minimalist web framework for Node.js.
- Mongoose: MongoDB object modeling for Node.js.
- jsonwebtoken: JSON Web Token implementation.
- MongoDB: NoSQL database.
- EJS: Embedded JavaScript templating.
This project is licensed under the MIT License.
Feel free to contribute to the project by opening issues or submitting pull requests. Your feedback and suggestions are highly appreciated.
- Special thanks to the authors and contributors of the dependencies used in this project.
For any questions or feedback, please contact paturkarabhishek03@gmail.com.
Happy coding!