A fully containerized RESTful API built using Node.js, Express, and MongoDB, packaged with Docker and Docker Compose for easy deployment and testing.
- REST API with Node.js + Express
- JWT authentication
- CRUD operations for Users and Posts
- MongoDB integration using Mongoose
- File Upload support
- Dockerized for consistent environments
- Postman Collection for API testing
| Layer | Technology |
|---|---|
| Backend | Node.js, Express |
| Database | MongoDB |
| Authentication | JWT (JSON Web Token) |
| Containerization | Docker, Docker Compose |
| API Testing | Postman |
restApiNode/
├── Dockerfile
├── docker-compose.yml
├── package.json
├── package-lock.json
├── src/
│ ├── app.js
│ ├── routes/
│ │ ├── user.js
│ │ └── posts.js
│ └── models/
│ ├── User.js
│ └── Post.js
└── data/ <-- MongoDB data volume
git clone https://github.com/jeevan520/restApiNode.git
cd restApiNodeMake sure Docker is installed and running. Then execute:
docker-compose up --buildThis will:
-
Build the Node.js image from the Dockerfile
-
Pull the official MongoDB 5 image
-
Start both containers:
my-node-app(API service)mongo(MongoDB database)
docker psYou should see both my-node-app and mongo running.
API will be available at:
http://localhost:5500
version: '3'
services:
app:
container_name: my-node-app
build: .
ports:
- '5500:5500'
depends_on:
- mongo
mongo:
container_name: mongo
image: mongo:5
volumes:
- ./data:/data/db
ports:
- '27017:27017'FROM node:latest
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install
COPY . .
CMD ["npm", "run", "dev"]| Command | Description |
|---|---|
docker-compose up --build |
Build and start containers |
docker-compose down |
Stop and remove containers |
docker ps |
List running containers |
docker logs my-node-app |
View Node.js logs |
docker exec -it mongo bash |
Access MongoDB shell |
You can easily test all endpoints using the Postman Collection included in this repository:
File: Rest_Express_apis.postman_collection.json
- Open Postman
- Click Import
- Choose the JSON collection file from the project
- The API requests will be imported automatically
| Method | Endpoint | Description | Auth |
|---|---|---|---|
POST |
/api/user/register |
Register a new user | ❌ |
POST |
/api/user/login |
Login user & get JWT token | ❌ |
GET |
/api/user/getUser/:id |
Get a user by ID | ✅ |
PUT |
/api/user/updateUser |
Update user details | ✅ |
DELETE |
/api/user/delete/:id |
Delete a user by ID | ✅ |
POST |
/api/user/getUsers |
Get all users | ✅ |
| Method | Endpoint | Description | Auth |
|---|---|---|---|
GET |
/api/posts/ |
Get all posts | ✅ |
GET |
/api/posts/lookUP |
Example lookup | ✅ |
PATCH |
/api/posts/:id |
Update a post by ID | ✅ |
DELETE |
/api/posts/:id |
Delete a post by ID | ✅ |
| Method | Endpoint | Description | Auth |
|---|---|---|---|
POST |
/api/upload |
Upload user avatar | ✅ |
POST http://localhost:5500/api/user/register
{
"name": "priya",
"email": "priya@gmail.com",
"password": "sripriya"
}POST http://localhost:5500/api/user/login
{
"email": "priya@gmail.com",
"password": "sripriya"
}Response:
{
"accessToken": "your-jwt-token"
}In Postman, add this header to protected routes:
auth-token: your-jwt-token
Now you can test:
/api/posts//api/user/getUsers/api/upload
MongoDB data is stored locally in:
./data
This ensures data remains even after the containers are stopped or rebuilt.
Contributions and improvements are welcome! Feel free to fork, open issues, or submit pull requests.
Jeevan 🔗 GitHub Profile
This project is open-source and available under the MIT License.