- Run
npm i
command - Export required env vars
export NODE_ENV='development'
export JWT_SECRET='not so super secret content'
export USER_SERVICE_URL='http://local-user-service-url'
export DB_USER='root'
export DB_PASSWORD='1234'
export REDIS_PASSWORD='1234'
export DOC_PATH='explorer'
export EXPOSE_SWAGGER_UI='true'
export EXPOSE_API_DOCS='true'
export API_PROTOCOL='http'
export API_HOSTNAME='localhost'
export API_PORT='80'
export API_PREFIX=''
- Add the following content to
CONFIG
env var for the development environment
{
"database": {
"type": "sqlite",
"database": "./database.sql"
},
"redis": {
"port": 6379,
"host": "localhost"
}
}
Example using quotes:
export CONFIG='{
"database": {
"type": "sqlite",
"database": "./database.sql"
},
"redis": {
"port": 6379,
"host": "localhost"
}
}'
- Run
npm start
command
- Run
npm i
command - Run
npm run build
command - Run
npm ci --production
command - Export required env vars
export NODE_ENV='production'
export JWT_SECRET='super secret content'
export USER_SERVICE_URL='http://user-service-url'
export DB_USER='admin'
export DB_PASSWORD='MDBP@sWoRd'
export REDIS_PASSWORD='R3d1sP@sWoRd'
export DOC_PATH='explorer'
export EXPOSE_SWAGGER_UI='false'
export EXPOSE_API_DOCS='true'
export API_PROTOCOL='https'
export API_HOSTNAME='node-service.com'
export API_PORT='80'
export API_PREFIX='service'
- Add the following content to
CONFIG
env var for the production environment
{
"database": {
"type": "mysql",
"host": "localhost",
"port": 3306,
"database": "db_name"
},
"redis": {
"port": 6379,
"host": "localhost"
}
}
Example using quotes:
export CONFIG='{
"database": {
"type": "mysql",
"host": "localhost",
"port": 3306,
"database": "db_name"
},
"redis": {
"port": 6379,
"host": "localhost"
}
}'
- Run
node build/src
command
- Run the following command to build the Docker Image
docker build -t <image-name>:<tag> .
- Set the
CONFIG
env var for production environment
export CONFIG='{
"database": {
"type": "mysql",
"host": "localhost",
"port": 3306,
"database": "db_name"
},
"redis": {
"port": 6379,
"host": "localhost"
}
}'
- Run the following command to run a Docker Container
docker run -dp <port>:80 \
-e NODE_ENV='production' \
-e JWT_SECRET='super secret content' \
-e USER_SERVICE_URL='http://user-service-url' \
-e DB_USER='root' \
-e DB_PASSWORD='1234' \
-e REDIS_PASSWORD='1234' \
-e CONFIG \
-e DOC_PATH='explorer' \
-e EXPOSE_SWAGGER_UI='false' \
-e EXPOSE_API_DOCS='true' \
-e API_PROTOCOL='https' \
-e API_HOSTNAME='node-service.com' \
-e API_PORT='80' \
-e API_PREFIX='service' \
<image>:<tag>
- Configure docker-compose.yml to suit the environment needs
- Run any of the following commands
# using old docker-compose CLI
docker-compose up
# using new built-in docker compose CLI
docker compose up
# run in a detached mode
docker compose up -d
- Configure kubernetes.yml to suit the environment needs
- Run the following command(s)
# run it inside the default namespace
kubectl apply -f kubernetes.yml
# run it inside a separate namespace
kubectl create namespace <namespace-name>
kubectl apply -f kubernetes.yml -n <namespace-name>
Env variable | Description | Example | Default |
---|---|---|---|
PORT | HTTP server listen port | 3000 |
80 |
NODE_ENV | Node configuration environment | production /development |
development |
DOC_PATH | Path of Swagger API doc | api-docs-ui |
explorer |
JWT_SECRET | JWT Secret | 5IUSD123JKJASA |
TOKEN |
USER_SERVICE_URL | URL of remote service | http://url-to-service |
null |
DB_USER | Database user | admin |
root |
DB_PASSWORD | Database password | pwd123 |
null |
REDIS_PASSWORD | Redis password | redpwd123 |
null |
API_PROTOCOL | Protocol of API server | https |
http |
API_HOSTNAME | Hostname of API server | node-service.com |
localhost |
API_PORT | Port of API server | 3000 |
80 |
API_PREFIX | Path prefix of API server | nodeService |
/ |
CONFIG | Additional configuration in JSON string format | {database: {...}, redis: {...}} |
null |
Lib | Description | URL |
---|---|---|
TypeScript | Statically typed language on top of JavaScript. | https://www.typescriptlang.org/docs/ |
Inversify.js | IoC container for JavaScript. | https://inversify.io/ |
socket.io | WebSocket lib for JavaScript. | https://socket.io/ |
Redis | JavaScript client lib for Redis. | https://redis.io/ |
Express | Node.js HTTP server. | https://expressjs.com/ |
Swagger JSDoc | API doc generator. | https://brikev.github.io/express-jsdoc-swagger-docs/ |
Mocha | JavaScript testing library. | https://mochajs.org/ |
Chai | JavaScript assertion library. | https://www.chaijs.com/ |
Sinon | Standalone test spies, stubs and mocks for JavaScript. | https://sinonjs.org/ |
Express Validator | Validation middleware for Express. | https://express-validator.github.io/docs/ |