https://github.com/maruf-pfc/users-crud-api
Users CRUD API with Nodejs, Express js, PostgreSQL, Docker and Joi
https://github.com/maruf-pfc/users-crud-api
crud-api docker pnpm swagger-docs unittest
Last synced: 11 months ago
JSON representation
Users CRUD API with Nodejs, Express js, PostgreSQL, Docker and Joi
- Host: GitHub
- URL: https://github.com/maruf-pfc/users-crud-api
- Owner: maruf-pfc
- License: apache-2.0
- Created: 2025-06-10T00:04:05.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-11T01:14:04.000Z (about 1 year ago)
- Last Synced: 2025-06-22T20:07:22.654Z (about 1 year ago)
- Topics: crud-api, docker, pnpm, swagger-docs, unittest
- Language: JavaScript
- Homepage:
- Size: 86.9 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 🧑💻 Users CRUD API
A full-featured Users CRUD REST API built with **Node.js**, **Express**, and **PostgreSQL**. Includes:
- Docker support
- Swagger API documentation
- Centralized error handling
- Postgres integration with both Docker and local **pgAdmin**
- Auto table creation on server start
## 🚀 Features
- ✅ RESTful API for user resource (CRUD)
- ✅ PostgreSQL database with Docker container
- ✅ Local database management using pgAdmin
- ✅ Swagger UI for API docs (`/api/v1/api-docs`)
- ✅ Modular structure (routes, controllers, models, middleware)
- ✅ Centralized error handler
- ✅ Auto-create tables on startup
- ✅ Environment variable support via `.env`
## 🧱 Tech Stack
- Node.js
- Express.js
- PostgreSQL
- Docker & Docker Compose
- pgAdmin
- Swagger (OpenAPI)
- ESLint (optional)
## 📁 Folder Structure
```txt
📦users-crud-api
┣ 📂.vscode
┃ ┗ 📜settings.json
┣ 📂public
┃ ┗ 📜vite.svg
┣ 📂src
┃ ┣ 📂configs
┃ ┃ ┣ 📜db.js
┃ ┃ ┗ 📜swagger.js
┃ ┣ 📂controllers
┃ ┃ ┗ 📜userController.js
┃ ┣ 📂database
┃ ┃ ┣ 📜createUserTable.js
┃ ┃ ┗ 📜db.sql
┃ ┣ 📂middlewares
┃ ┃ ┣ 📜errorHandler.js
┃ ┃ ┗ 📜validate.js
┃ ┣ 📂models
┃ ┃ ┗ 📜userModel.js
┃ ┣ 📂routes
┃ ┃ ┗ 📜userRoutes.js
┃ ┣ 📂utils
┃ ┃ ┗ 📜logger.js
┃ ┣ 📂validations
┃ ┃ ┗ 📜userValidation.js
┃ ┣ 📜app.js
┃ ┗ 📜server.js
┣ 📜.dockerignore
┣ 📜.env
┣ 📜.env.example
┣ 📜.gitignore
┣ 📜.prettierignore
┣ 📜.prettierrc
┣ 📜Dockerfile
┣ 📜LICENSE
┣ 📜README.md
┣ 📜docker-compose.yaml
┣ 📜index.html
┣ 📜package.json
┣ 📜pnpm-lock.yaml
┣ 📜users-crud-api.json
┗ 📜vite.config.js
```
## ⚙️ Environment Variables
Create a `.env` file at the root:
```env
PORT=5000
DB_HOST=db
DB_PORT=5432
DB_USER=postgres
DB_NAME=users_db
DB_PASSWORD=your_password
```
## 🐳 Docker Setup
### Start containers
```bash
docker-compose up --build
```
This sets up:
- PostgreSQL database
- pgAdmin (on port `5432`)
- Your Node.js app (on `http://localhost:5000/api/v1/`)
## 📦 API Endpoints
Base URL: `http://localhost:5000/api/v1`
| Method | Endpoint | Description |
| ------ | ----------- | -------------------- |
| GET | `/users` | Get all users |
| GET | `/users/:id` | Get user by ID |
| POST | `/users` | Create new user |
| PUT | `/users/:id` | Update existing user |
| DELETE | `/users/:id` | Delete a user |
## 🧪 Swagger Docs
Access at: `http://localhost:5000/api/v1/api-docs`
```js
// Swagger setup path in app.js
app.use('/api/v1/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
```
## 🛠️ Scripts
```bash
# Start server
npm run dev
# Build & run Docker containers
docker-compose up --build
```
## ✅ To Do
- [x] Write unit tests
- [ ] Write integration tests
- [x] Add CI/CD with GitHub Actions
## 🤝 Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
## 📄 License
[Apache License](LICENSE)
## 👨💻 Author
**Md. Maruf Sarker**
Community Manager | Software Engineer | Content Creator
🔗 [GitHub](https://github.com/maruf-pfc) | 🌐 [LinkedIn](https://linkedin.com/in/mdmarufsarker)