A lightweight and robust authentication system built with Node.js and Express.js. It includes features such as user registration, login, password hashing, and JWT-based authentication.
- User registration with validation.
- Secure password hashing using bcrypt.
- Token-based authentication using JWT.
- Middleware for protected routes.
- Ready-to-use API endpoints for authentication.
- Clone the repository:
git clone https://github.com/detayotella/node-express-auth.git
cd node-express-auth
- Install dependencies:
npm install
- Create a .env file with the following variables:
PORT=3000
MONGO_URI=your-mongodb-connection-string
JWT_SECRET_KEY=JWT_SECRET_KEY
CLOUDINARY_CLOUD_NAME=CLOUDINARY_CLOUD_NAME
CLOUDINARY_API_KEY=CLOUDINARY_API_KEY
CLOUDINARY_API_SECRET=CLOUDINARY_API_SECRET
- Start the development server:
npm run dev
Method | Endpoint | Description |
---|---|---|
POST |
/api/register |
Register a new user |
POST |
/api/login |
Authenticate a user |
GET |
/api/image/get |
fetch uploaded images |
GET |
/api/admin/welcome |
Authenticate an admin |
POST |
/api/image/upload |
Upload an Image |
GET |
api/admin/welcome |
Admin welcome page |
GET |
api/home/welcome |
Home page |
DELETE |
api/image/delete |
Delete an image |
POST |
/api/auth/change-password |
Change password |
- Node.js
- Express.js
- MongoDB
- bcrypt
- jsonwebtoken