This project provides a foundational setup for generating JSON Web Tokens (JWT) to access RESTful APIs using Node.js and MongoDB. The application is built with Express.js and includes user authentication functionality.
- User Authentication: Secure user login and registration using JWT.
- API Endpoints: RESTful APIs for user management and authentication.
- Database Integration: MongoDB for data storage.
- Dependencies:
- bcryptjs for password hashing.
- body-parser for parsing request bodies.
- express for server setup.
- jsonwebtoken for token generation and validation.
- mongoose for MongoDB interaction.
- Clone the repository:
git clone https://github.com/Progesh/nodejs-jwt-mongodb.git cd nodejs-jwt-mongodb
- Install the dependencies:
npm install
- Start the MongoDB server:
mongod
- Start the Node.js server:
node server.js
- Test the APIs using tools like Postman.
- app.js: Main application entry point. Configures routes for user and authentication functionalities.
- user/UserController.js: Handles user-related routes and operations.
- auth/AuthController.js: Implements authentication logic, including login and token validation.
- db.js: Database connection setup for MongoDB.
- POST /users/register: Register a new user.
- GET /users: Retrieve a list of users.
- POST /api/auth/login: User login and token generation.
- GET /api/auth/validate: Validate a JWT.