@@ -19,6 +19,9 @@ A boilerplate/starter project for quickly building RESTful APIs using Node.js,Ty
1919 - [ Manual Installation] ( #manual-installation )
2020 - [ Getting started] ( #getting-started )
2121 - [ For development] ( #for-development )
22+ - [ Docker Setup] ( #docker-setup )
23+ - [ Using Docker Compose (Recommended)] ( #using-docker-compose-recommended )
24+ - [ Using Docker Only] ( #using-docker-only )
2225 - [ Sample .ENV] ( #sample-env )
2326 - [ Commands] ( #commands )
2427 - [ Project Structure] ( #project-structure )
@@ -84,6 +87,113 @@ npm run dev
8487
8588```
8689
90+ ## Docker Setup
91+
92+ ### Using Docker Compose (Recommended)
93+
94+ The easiest way to run the application with Docker is using Docker Compose, which will set up both the Node.js application and PostgreSQL database.
95+
96+ 1 . ** Create a ` .env ` file** in the project root:
97+
98+ ``` bash
99+ # Database Configuration
100+ DB_HOST=postgres
101+ DB_PORT=5432
102+ DB_TYPE=postgres
103+ DB_NAME=myapp
104+ DB_USER=postgres
105+ DB_PASSWORD=password
106+
107+ # JWT Configuration
108+ SECRET=your-secret-key-change-this-in-production
109+ TOKEN_EXPIRY_HOUR=24
110+
111+ # Email Configuration
112+ EMAIL_SERVICE=gmail
113+ EMAIL_USER=your-email@gmail.com
114+ EMAIL_PASS=your-email-password
115+ EMAIL_FROM=your-email@gmail.com
116+
117+ # OTP Configuration
118+ OTP_EXPIRY_MIN=5
119+ OTP_SECRET=your-otp-secret-change-this-in-production
120+ ```
121+
122+ 2 . ** Build and run the containers** :
123+
124+ ``` bash
125+ # Build and start all services
126+ docker compose up --build
127+
128+ # Run in detached mode (background)
129+ docker compose up -d --build
130+
131+ # Stop the services
132+ docker compose down
133+
134+ ```
135+
136+ 3 . ** Access the application** :
137+ - ** API** : http://localhost:5000/api/
138+ - ** Swagger Documentation** : http://localhost:5000/api/v1/docs/
139+ - ** Database** : PostgreSQL on localhost:5432
140+
141+ ### Using Docker Only
142+
143+ If you prefer to run only the application container and connect to an external database:
144+
145+ 1 . ** Build the Docker image** :
146+
147+ ``` bash
148+ docker build -t typescript-node-app .
149+ ```
150+
151+ 2 . ** Run the container** :
152+
153+ ``` bash
154+ docker run -p 5000:5000 \
155+ -e DB_HOST=your-db-host \
156+ -e DB_PORT=5432 \
157+ -e DB_TYPE=postgres \
158+ -e DB_NAME=your-db-name \
159+ -e DB_USER=your-db-user \
160+ -e DB_PASSWORD=your-db-password \
161+ -e SECRET=your-secret-key \
162+ -e TOKEN_EXPIRY_HOUR=24 \
163+ -e EMAIL_SERVICE=gmail \
164+ -e EMAIL_USER=your-email@gmail.com \
165+ -e EMAIL_PASS=your-email-password \
166+ -e EMAIL_FROM=your-email@gmail.com \
167+ -e OTP_EXPIRY_MIN=5 \
168+ -e OTP_SECRET=your-otp-secret \
169+ typescript-node-app
170+ ```
171+
172+
173+ ### Docker Commands
174+
175+ ``` bash
176+ # Build the image
177+ docker build -t typescript-node-app .
178+
179+ # Run container
180+ docker run -p 5000:5000 typescript-node-app
181+
182+ # Run with environment file
183+ docker run -p 5000:5000 --env-file .env typescript-node-app
184+
185+ # View running containers
186+ docker ps
187+
188+ # View logs
189+ docker logs < container-id>
190+
191+ # Stop container
192+ docker stop < container-id>
193+
194+ ```
195+
196+
87197## Sample .ENV
88198``` sh
89199DB_HOST=localhost
@@ -128,6 +238,9 @@ npm run lint
128238# format files
129239npm run format
130240
241+ # Docker commands
242+ docker compose up --build
243+ docker compose down
131244```
132245
133246
149262 |--validations\ # Request data validation schemas
150263 |--app.ts\ # Express app
151264 |--server.ts\ # App entry point
265+ docker-compose.yml # Docker Compose configuration
266+ Dockerfile # Docker image definition
267+ .env # Environment variables
152268```
153269## Changing Database
154270
0 commit comments