A comprehensive RESTful API built with the MERN stack, offering robust authentication and user management features.
-
🔐 Secure Authentication
- User registration and login
- JWT-based token authentication
- Secure password encryption
- Protected routes
-
🛡️ User Management
- Create, Read, Update, and Delete (CRUD) user operations
- User profile management
- Role-based access control
-
🔒 Security Measures
- JWT token authentication
- Bcrypt password hashing
- Middleware route protection
- Comprehensive error handling
- Backend: Node.js, Express.js
- Database: MongoDB
- Authentication: JWT (JSON Web Tokens)
- Password Encryption: Bcrypt
- Node.js (v14 or later)
- MongoDB
- npm or yarn
git clone https://github.com/Zilean12/RESTful-API.git
cd RESTful-API
# Install dependencies
npm install
# Create environment variables
cp .env.example .env
Create a .env
file in the backend
directory:
# Server Configuration
PORT=5000
MONGODB_URI=mongodb://localhost:27017/yourdatabase
JWT_SECRET=your_very_secret_and_long_random_string
NODE_ENV=development
# Google OAuth Configuration
GOOGLE_CLIENT_ID=your_google_oauth_client_id
GOOGLE_CLIENT_SECRET=your_google_oauth_client_secret
GOOGLE_CALLBACK_URL=http://localhost:5000/api/auth/google/callback
- Go to the Google Cloud Console
- Create a new project or select an existing one
- Navigate to "APIs & Services" > "Credentials"
- Create a new OAuth 2.0 Client ID
- Set up the authorized redirect URIs
- Copy the Client ID and Client Secret into your
.env
file
# Start the application
npm start
Method | Endpoint | Description |
---|---|---|
POST |
/api/auth/register |
Register a new user |
POST |
/api/auth/login |
User login |
POST |
/api/auth/logout |
User logout |
GET |
/api/auth/me |
Get user profile |
Method | Endpoint | Description |
---|---|---|
GET |
/api/users/ |
Get all users (protected) |
GET |
/api/users/:id |
Get user by ID (protected) |
PUT |
/api/users/:id |
Update user (protected) |
DELETE |
/api/users/:id |
Delete user (protected) |
- Register a new user
- Login and receive JWT token
- Use token in Authorization header for protected routes
- Header Key:
Authorization
- Header Value:
Bearer your_jwt_token
- Header Key:
- JWT-based authentication
- Password hashing with bcrypt
- Protected routes
- Token-based logout
- Comprehensive error handling middleware
- Ensure MongoDB is running
- Verify
.env
file configuration - Check Node.js and npm versions
This project is open-source and available under the MIT License.
Contributions are welcome! Please check the GitHub repository for contribution guidelines.
Happy Coding! 👨💻👩💻