Skip to content

vukhanhtruong/nodejs-api-boilerplate

Repository files navigation

Prerequisite

  1. NodeJS
  2. Node Package Management (yarn or npm)
  3. Docker

Installation

  1. Clone the project git clone git@github.com:vukhanhtruong/nodejs-api-boilerplate.git.
  2. Install dependencies yarn install or npm i
  3. Copy .env.example to .env file.

Running Docker

docker-compose up -d.


Raven Log

Create account at Sentry, then put your url to .env file at variable SENTRY_DSN.


Api Doc

Api doc his hosted on surge. For change the url and have your own docs just modify your link in the .env file. Running the following command to publish your documentation.

# Generate document
yarn doc
# Deploy document to surge.sh
yarn doc:deploy

# or
npm run doc
npm run doc:deploy

Pre-Commit Hook

Using husky for linting your code before commit & running unit test before push.


Scripts

DEV

yarn dev

# or

npm run dev

DEBUG

Debug with VSCode. See VSCode Auto-Attach

yarn debug

# or

npm run debug

TEST

yarn test

# or

npm run test

NOTE: If you have the issue with ENOSPC, run the below command to avoid:

echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

Test Watch

yarn test:watch

COVERAGE

# run jest coverage
yarn test:cover

# show html report
yarn test:cover:open

# or

npm run test:cover

npm run test:cover:open

JSDOC

# generate documentation
yarn doc

# Publish documentation to surge.sh
yarn doc:deploy

#or

npm run doc

npm run doc:deploy

Deployment

Heroku Configuration

Generate heroku token. Then add this token to Gitlab CI Variables as HEROKU_TOKEN

heroku auth:token

Gitlab CI & CD

Code will automatically test & deploy to Heroku after merging into development branch.

To test gitlabCI on locally, run the following command

# to run test service
gitlab-runner exec docker test

# to run deployment service
gitlab-runner exec docker development --docker-privileged

References


About

Structuring Node.js RESTful API with ES6, JWT, and some of useful tech...

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published