A robust authentication service built with Node.js, Express, and MongoDB. This service provides user registration, login, and authentication functionality using JWT (JSON Web Tokens).
- User registration and login
- JWT-based authentication
- Password hashing with bcrypt
- MongoDB database integration
- CORS support
- Cookie session management
- Node.js (v14 or higher)
- MongoDB
- Docker and Docker Compose (optional, for containerized deployment)
- Clone the repository:
git clone <your-repository-url>
cd express-auth-service- Install dependencies:
npm install- Set up environment variables:
Create a
.envfile in the root directory with the following variables:
MONGODB_URI=your_mongodb_connection_string
JWT_SECRET=your_jwt_secret_key
PORT=3000
npm run devnpm startdocker-compose upPOST /api/auth/register- Register a new userPOST /api/auth/login- Login userPOST /api/auth/logout- Logout userGET /api/auth/verify- Verify JWT token
express-auth-service/
├── app/
│ ├── controllers/ # Route controllers
│ ├── middleware/ # Custom middleware
│ ├── models/ # Database models
│ └── routes/ # API routes
├── docker-compose.yml # Docker configuration
├── package.json # Project dependencies
└── server.js # Application entry point
- express: ^4.18.2
- mongoose: ^6.10.0
- jsonwebtoken: ^9.0.2
- bcryptjs: ^2.4.3
- cors: ^2.8.5
- cookie-session: ^2.1.0
- body-parser: ^1.20.2
- Password hashing using bcrypt
- JWT token-based authentication
- CORS protection
- Secure cookie session management
ISC
jvegar