VSCODE
specified editor settingsNode v16.x
Typescript v4.7
Yarn classic
for the package managerPostgres 12
with Typeorm libraryRedis
pre-containerized- Bree for worker thread
- Koa for basic webserver
Docker
for the database and test env container (Install Docker Desktop recommended)- Prepared PM2 multi process deployment using
PM2_INDEX
andPM2_INSTANCE_NUM
onsrc/config.ts
file - Default exposed ports below, You can change this by modifing
docker-compose.yml
file andsrc/config.ts
file
POSTGRES_DB: 5433
REDIS: 6380
WEB_SERVER: 4000
Step 1. Install Docker Desktop for running Postgres and Redis
(included .prettierrc.json
file will match the format automatically)
You should see .vscode/settings.json
on your directory with below contents
// Or just create file and paste below lines.
{
"editor.formatOnSave": true,
"eslint.format.enable": false,
"editor.tabSize": 2
}
1. CTRL + SHIFT + P
2. Format Document (in pop-up bar)
3. Select Format Document
4. Select Configure Default Formatter...
5. Select Prettier - Code formatter
This repository has 3 different env settings using DotENV
library.
You can specify envionment append ENV flag as prefix of the command
ex) ENV=production, ENV=local-prod, ENV=local
ㄴ Basic local config.
Default values will inject if there is no env flag (set on src/config.ts
file)
ㄴ For connect production database on local computer. (Example)
Save as local-prod.env
!!! DO NOT ADD THIS FILE ON GIT !!!
PORT=4000
ENV=production
JWT_SECRET=Example
DB_TYPE=postgres
DB_USER=Example
DB_PASSWORD=Example
DB_HOST=Example
DB_PORT=5432
DB_NAME=project
REDIS_HOST=Example
REDIS_PORT=6379
ㄴ For the production. (Example)
Save as production.env
!!! DO NOT ADD THIS FILE ON GIT !!!
PORT=4000
ENV=production
JWT_SECRET=Example
DB_TYPE=postgres
DB_USER=Example
DB_PASSWORD=Example
DB_HOST=Example
DB_PORT=5432
DB_NAME=project
REDIS_HOST=Example
REDIS_PORT=6379
$ yarn install
$ docker-compose up -d
$ SYNC=True yarn schema-sync
# Init postgres database model.
# SYNC=True flag enables modifing database schema.
# This flag exist for migration production db from local computer
# using typescript entity file directly.
# For more description, please visit src/config.ts file.
$ yarn watch-start
# This script detect source code's change and automatically restart server
To execute this project as production build, You should create your environment file following above environment injection section
$ yarn build
$ ENV=production yarn start
-
For insure independent envionment, We use Docker container for the test instance.
./src, ./__test__, ./package.json
files local change will apply immediately on the container. -
IMPORTANT:
When local./package.json
changes, You MUST executeyarn install
inside the container or re-build container. Because packages are installed depending system architecture. Sonode_modules
folder is not synced between local and container.
$ docker-compose up -d
$ docker exec -it typescript-boilerplate-test /bin/bash
(container) $ yarn test
$ docker-compose build --no-cache
-
If
SYNC=True yarn schema-sync
fails with datasource error, please runyarn schema-log
first.
Quite sure there is an error on database entity model or database connection settings. -
src/playground.ts
file is for the placeholder.
Since this file work as code playground, I recommend add this file on.gitignore
. (Currently commented out)