https://github.com/valentinocarmonas/api-crud
https://github.com/valentinocarmonas/api-crud
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/valentinocarmonas/api-crud
- Owner: ValentinoCarmonaS
- License: mit
- Created: 2025-04-08T12:26:14.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2025-04-21T18:23:08.000Z (6 months ago)
- Last Synced: 2025-04-21T18:41:23.084Z (6 months ago)
- Language: JavaScript
- Size: 224 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# API CRUD

[](https://codecov.io/gh/ValentinoCarmonaS/API-CRUD)A **RESTful API** built with **Node.js**, **Express**, and **MongoDB**,
implementing the **MVC** pattern. It supports **CRUD** operations for user
management and includes **JWT authentication** for secure access. Designed for
scalability, thoroughly tested, and easy to deploy.## ๐ Features
- **CRUD Operations**: Create, read, update, and delete users.
- **Authentication**: Secure endpoints with JWT-based authentication.
- **MongoDB**: NoSQL database integration with MongoDB Atlas.
- **Testing**: Comprehensive tests with Jest and Supertest (93.75% branch
coverage).
- **Docker**: Containerized setup for easy deployment.## ๐ Prerequisites
- **Node.js** v16+
- **Docker** and **Docker Compose** (optional, for containerized setup)
- **MongoDB Atlas** account or local MongoDB instance## ๐ ๏ธ Installation
1. Clone the repository:
```bash
git clone https://github.com/ValentinoCarmonaS/API-CRUD.git
cd API-CRUD
```2. Install dependencies:
```bash
npm install
```3. Create a `.env` file in the root directory with:
```bash
PORT=3000
MONGODB_URI=mongodb+srv://:@cluster0.mongodb.net/api-crud?retryWrites=true&w=majority
JWT_SECRET=your_jwt_secret
```## โถ๏ธ Running the API
- **Locally**:
```bash
npm start
```The API will be available at `http://localhost:3000/api`.
- **With Docker**:
```bash
make build
make up
```
Stop containers with:
```bash
make down
```## ๐งช Testing
Run tests with Docker:
```bash
make test
```Or run test with npm:
```bash
npm test
```- Tests cover authentication, user CRUD, and global middleware logic.
- Coverage: 93.75% branches, 98.64% statements.
- View detailed reports in `coverage/lcov-report/index.html`.## ๐ API Endpoints
- **Auth**:
- `POST /api/auth/register`: Register a new user.
- `POST /api/auth/login`: Authenticate and receive a JWT.
- **Users** (JWT required):
- `GET /api/users`: List all users.
- `GET /api/users/:id`: Get a user by ID.
- `POST /api/users`: Create a user.
- `PUT /api/users/:id`: Update a user.
- `DELETE /api/users/:id`: Delete a user.For detailed endpoint documentation, refer to the
[API specification](docs/api-spec.md).## ๐๏ธ Project Structure
```
API-CRUD/
โโโ src/
โ โโโ config/ # Database and environment setup
โ โโโ controllers/ # Business logic for endpoints
โ โโโ middlewares/ # Authentication and validation
โ โโโ models/ # MongoDB schemas
โ โโโ routes/ # API endpoint definitions
โ โโโ tests/ # Jest and Supertest tests
โ โโโ app.js # Express app setup
โโโ .env # Environment variables
โโโ Dockerfile # Docker configuration
โโโ docker-compose.yml # Docker Compose setup
โโโ Makefile # Automation scripts
โโโ package.json # Dependencies and scripts
```## ๐ License
[MIT](LICENSE)