https://github.com/zilean12/restful-api
MERN Stack RESTful API with Authentication
https://github.com/zilean12/restful-api
authentication crud-application mern-stack mongodb nodejs postman
Last synced: 7 months ago
JSON representation
MERN Stack RESTful API with Authentication
- Host: GitHub
- URL: https://github.com/zilean12/restful-api
- Owner: Zilean12
- Created: 2024-12-02T17:06:52.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-12-07T04:00:00.000Z (10 months ago)
- Last Synced: 2025-03-28T20:17:13.260Z (7 months ago)
- Topics: authentication, crud-application, mern-stack, mongodb, nodejs, postman
- Language: JavaScript
- Homepage:
- Size: 56.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ๐ MERN Stack RESTful API with Authentication
## ๐ Project Overview
A comprehensive RESTful API built with the MERN stack, offering robust authentication and user management features.
## โจ Key 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## ๐ ๏ธ Technology Stack
- Backend: Node.js, Express.js
- Database: MongoDB
- Authentication: JWT (JSON Web Tokens)
- Password Encryption: Bcrypt## ๐ง Prerequisites
- Node.js (v14 or later)
- MongoDB
- npm or yarn## ๐ฆ Installation
### 1. Clone the Repository
```bash
git clone https://github.com/Zilean12/RESTful-API.git
cd RESTful-API
```### 2. file Setup
```bash
# Install dependencies
npm install# Create environment variables
cp .env.example .env
```### 3. Configure Environment Variables
Create a `.env` file in the `backend` directory:
```env
# 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
```### Google OAuth Setup
1. Go to the [Google Cloud Console](https://console.cloud.google.com/)
2. Create a new project or select an existing one
3. Navigate to "APIs & Services" > "Credentials"
4. Create a new OAuth 2.0 Client ID
5. Set up the authorized redirect URIs
6. Copy the Client ID and Client Secret into your `.env` file### 4. Run the Application
```bash
# Start the application
npm start
```## ๐ API Endpoints
### Authentication Endpoints
| 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 |### User Management Endpoints
| 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) |## ๐งช Postman Testing
1. Register a new user
2. Login and receive JWT token
3. Use token in Authorization header for protected routes
- Header Key: `Authorization`
- Header Value: `Bearer your_jwt_token`## ๐ก๏ธ Security Features
- JWT-based authentication
- Password hashing with bcrypt
- Protected routes
- Token-based logout
- Comprehensive error handling middleware## ๐จ Troubleshooting
- Ensure MongoDB is running
- Verify `.env` file configuration
- Check Node.js and npm versions## ๐ License
This project is open-source and available under the MIT License.
## ๐ Contributing
Contributions are welcome! Please check the GitHub repository for contribution guidelines.
---
**Happy Coding! ๐จโ๐ป๐ฉโ๐ป**