A Node.js/Express backend service that provides authentication endpoints for user registration and login. This backend works in conjunction with an Angular frontend application.
- User Registration (Signup)
- User Authentication (Login)
- Password Hashing with bcrypt
- JWT Token Generation
- MongoDB Integration
- CORS Support
- Input Validation
- Node.js
- Express.js
- MongoDB
- Mongoose
- JWT (jsonwebtoken)
- bcrypt
- cors
- Node.js (Latest LTS version)
- MongoDB installed and running locally
- npm (Node Package Manager)
- Clone the repository
- Install dependencies:
npm installThe application uses the following default configurations:
- MongoDB URL:
mongodb://localhost:27017/ahmed - Server Port: 3000
- JWT Secret Key: "your-secret-key-here" (Should be changed in production)
- URL:
/api/signup - Method: POST
- Body:
{
"name": "string",
"email": "string",
"password": "string"
}- URL:
/api/login - Method: POST
- Body:
{
"email": "string",
"password": "string"
}- Success Response: Returns JWT token and user information
Start the server:
node index.js- Password hashing using bcrypt
- JWT token-based authentication
- Input validation and sanitization
- CORS protection
This backend is designed to work with an Angular frontend application. The frontend repository contains the user interface for registration and login functionality.
The API includes comprehensive error handling for:
- Invalid credentials
- Duplicate email addresses
- Database connection issues
- Validation errors
- name (String, required, 3-50 characters)
- email (String, required, unique, 5-255 characters)
- password (String, required, 5-1024 characters, hashed)
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a new Pull Request