/express-app-template

A template for express app that utilize babel, jest, eslint, prettier, husky ....

Primary LanguageJavaScript

express-app-template

This is the template for Node project which has ExpressJS as backend framework.

What this project has been setup:

Get Started

Requirements:

  • Node (version 12)
  • Yarn
  • Docker (for building docker image)

Note: You can use nvm to switch between node versions easily.

Clone project:

git clone git@github.com:PercyPham/express-app-template.git [your-app-name]

Development

Recommend using VSCode for developing this project.

After installing VSCode, add extra extensions to VSCode:

Config VSCode's workspace settings as below:

{
  "settings": {
    "window.zoomLevel": 1,
    "editor.formatOnSave": true,
    "eslint.autoFixOnSave": true
  }
}

Install dependencies before starting development:

yarn install

Start project in development mode:

yarn dev

Convention

Coding

This project already has lint set up.

To check lint for your code, run:

yarn lint

Check and fix your code before commit:

yarn lint:fix

Test

Run tests

Note: Test code will get env variables defined in .env.test file.

Unit test:

# normal run
yarn test:unit

# run in watch mode
yarn test:unit --watch

Integration test

yarn test:integration

All test with coverage report (visual result will be placed in .coverage folder at same level with this README file)

yarn test:coverage

Write tests

All test file should be placed under __tests__ folder next to its tested function file. Test files can also be placed inside test folder.

Unit test file name must be end with .unit.test.js

Integration test file name must be end with .int.test.js

For example:

utilFunc
├── __tests__
│   └── utilFunc.unit.test.js
├── utilFunc.js
└── index.js

Build

Before building make a copy of .env.dev and name it .env

And then change its content accordingly.

Build Code Locally

Run:

yarn build

Note: this will output the built folder dist.

To run the built code, simply run:

yarn start

Build Docker Image

Run:

docker build -t [your-app-name] .

Run container:

docker run -p 5000:5000 [your-app-name]

Note: suppose your app use default port 5000 (not defined it in .env file).