Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ jobs:
node:
- 18
- 20
- 21
- 22
- 23
- 24
os:
- ubuntu-latest
Expand Down
19 changes: 13 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
FROM node:20-alpine
FROM node:18-alpine

WORKDIR /usr/server
COPY package*.json .
RUN npm ci --only=production

COPY package*.json ./

RUN npm ci --only=production && npm cache clean --force

COPY . .
EXPOSE 8000
EXPOSE 8001
EXPOSE 8002

EXPOSE 8000 8001 8002

HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD node -e "require('http').get('http://localhost:8000/health', (res) => { process.exit(res.statusCode === 200 ? 0 : 1) }).on('error', () => process.exit(1))"

CMD ["node", "server.js"]
60 changes: 57 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,69 @@ let's start with

## Usage

- You need node.js 18.x or 20.x
- You need Node.js 18.x or higher (24.x preferred)
- Fork and clone this repository (optionally subscribe to repo changes)
- Run `npm i` to install dependencies and generate RSA certificate
- Remove unneeded dependencies if your project doesn't require them
- Add your license to `LICENSE` file but don't remove starter kit license
- Start your project modifying this starter kit
- If you have Docker and Docker Compose installed to run the project, use the command: `docker-compose up`

## Docker Usage

The easiest way to run this application is using Docker and Docker Compose:

### Prerequisites

- Docker and Docker Compose installed
- No need to install PostgreSQL or Redis locally
- Uses PostgreSQL 17 (latest stable) and Redis 8

### Quick Start

```bash
# Start all services (API, PostgreSQL, Redis)
docker-compose up

# Start services in background (detached mode)
docker-compose up -d

# Stop all services
docker-compose down

# View logs
docker-compose logs

# View logs for specific service
docker-compose logs api-example
docker-compose logs pg-example
docker-compose logs redis-example

# Rebuild and start services
docker-compose up --build -d
```

### Access Points

- **Main Application**: http://localhost:8002/ (Metarhia Console)
- **API Endpoints**: http://localhost:8001/api/
- **Load Balancer**: http://localhost:8000/ (redirects to 8002)

### Service Status

```bash
# Check running services
docker-compose ps

# Restart a specific service
docker-compose restart api-example
```

## Manual Installation (Alternative)

If you prefer to run without Docker:

- Before running server initialize the DB:
- First of all, make sure you have PostgreSQL installed (preferably 12.x to 16.x).
- First of all, make sure you have PostgreSQL installed (preferably 15.x to 17.x).
- Run database initialization script: `database/setup.sh`
- Run project: `node server.js` and stop with Ctrl+C
- Ask questions in Telegram https://t.me/nodeua (node.js related) or
Expand Down
25 changes: 11 additions & 14 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3'

services:
api-example:
build:
Expand All @@ -9,39 +7,38 @@ services:
environment:
- DB_HOST=pg-example
- REDIS_HOST=redis-example
volumes:
- ./application:/usr/server/application
depends_on:
- pg-example
- redis-example
ports:
- 127.0.0.1:8000:8000
- 127.0.0.1:8001:8001
- 127.0.0.1:8002:8002
- "127.0.0.1:8000:8000"
- "127.0.0.1:8001:8001"
- "127.0.0.1:8002:8002"
restart: always

pg-example:
image: postgres:16.1-alpine3.19
image: postgres:17-alpine
container_name: pg-example
environment:
- POSTGRES_USER=marcus
- POSTGRES_PASSWORD=marcus
- POSTGRES_DB=application
volumes:
- ./data/postgres/:/var/lib/postgresql/data
- ./database/structure.sql:/docker-entrypoint-initdb.d/1.sql
- ./database/data.sql:/docker-entrypoint-initdb.d/2.sql
- postgres_data:/var/lib/postgresql/data
ports:
- 127.0.0.1:5432:5432
- "127.0.0.1:5432:5432"
restart: always

redis-example:
image: redis:7-alpine
image: redis:8-alpine
container_name: redis-example
ports:
- 127.0.0.1:6379:6379
- "127.0.0.1:6379:6379"
restart: always

volumes:
postgres_data:

networks:
default:
name: api-example-network
Loading