This repository contains a Node.js application that uses PostgreSQL and Redis, and is Dockerized for easy deployment.
I've written a blog on how can you dockerize this Node.js app & run in docker. This reposirity contains the exampke codebase for this blog so check this blog for the better understanbding:
Dockerizing Node.js REST API with Postgres and Redis
Before running the application, make sure you have Docker installed:
- Docker: Install Docker
Follow these steps to run the Node.js application with PostgreSQL and Redis in Docker:
-
Clone this repository:
git clone https://github.com/tazbin/blog-website-backend-nodejs-REST-API nodejs-docker
-
Navigate to the repository:
cd nodejs-docker -
make a
.envfile following the format of.env.examplefile and set the values -
build docker images & run containers
docker-compose up --build
-
view running containers
docker ps
docker-compose down - Method:
GET - URL:
localhost:3000 - Description: Just shows hello world
- Response status:
200 OK - Response Payload:
Hello World!
- Method:
POST - URL:
localhost:3000/users - Description: Creates a new user
- Request Payload:
{ "name": "Tazbinur", "age": 25 } - Response status:
200 OK - Response Payload:
{ "id": 1, "name": "Tazbinur", "age": 25, "updatedAt": "2024-04-25T16:24:26.490Z", "createdAt": "2024-04-25T16:24:26.490Z" }
- Method:
GET - URL:
localhost:3000/users - Description: Gets list of saved users
- Response status:
200 OK - Response Payload:
[ { "id": 1, "name": "Tazbinur", "age": 25, "createdAt": "2024-04-20T18:57:54.001Z", "updatedAt": "2024-04-20T18:57:54.001Z" }, { "id": 2, "name": "Imtiaz", "age": 30, "createdAt": "2024-04-20T18:58:08.331Z", "updatedAt": "2024-04-20T18:58:08.331Z" } ]