This NodeJS template includes the bare minimum setup to help you get started. We didn't try to guess what you are going to do based on this template, so we didn't configure any web-server or cron-job related tooling (although you can do it quite easily based on what's already in place). Nevertheless, If you want to build an express app, please check out our nodejs-ts-express template.
We're using ESLint for code style checks and Prettier for file formatting checks. The setup of each of them is described below.
Prettier is configured with a minimum set of rules, such as tabWidth
and arrowParens
preferences:
{
"tabWidth": 2,
"arrowParens": "avoid",
"singleQuote": true,
"printWidth": 100
}
Feel free to extend this config as your team feels fit.
ESLint was configured to use the standard recommended setup (standard-with-typescript
) and to extend prettier rules, so there's no conflict between the two. The config file looks like this:
{
"env": {
"browser": true,
"es2021": true
},
"extends": ["standard-with-typescript", "prettier"],
"ignorePatterns": ["dist/**/*.js"],
"overrides": [],
"parserOptions": {
"project": ["tsconfig.json"],
"ecmaVersion": "latest",
"sourceType": "module"
},
"rules": {}
}
In order to provide commit coherence between contributors, a set of commit rules were put in place. Using conventional commits as a base and some automation provided by commitizen, git-cz and commitlint, contributors are free to either choose to handcraft a conventional commit message using git commit
or to use yarn cmt
and use a commit assistant to make sure their messages are well-formatted.
To make sure the codebase remains clean and healthy, a set of pre-commit hooks were added. Each of them are described below.
To make sure that commit messages remain compliant to the conventional commits convention, commitlint
was configured. It will fail the commit in case we try to add a malformed message.
We're also running a prettier:check
to detect malformed files, ESLint to detect code style violations, and all the unit tests to make sure the test suite is green and consistent.
Jest was the chosen test engine to run our unit tests. A simple test was added to src
to make sure everything is working fine.
A simple GitHub Actions integration pipeline was configured. It installs the dependencies, checks code formatting and style, runs the tests and builds the project. It looks like:
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: npm install
- name: Check formatting
run: npm run prettier:check
- name: Check code style
run: npm run lint
- name: Build project
run: npm run build
- name: Run unit tests
run: npm run test
Considering all the topics above, the full list of available scripts are:
dev
: usests-node-dev
to transpile the code in-memory for developmentbuild
erases everything in thedist
directory and recreate it usingtsc
(the typescript compiler)start
: starts the application from thedist
directory (make sure to runyarn build
first)test
: runs all the unit testsprettier:check
: perform Prettier checks at thesrc
directoryprettier:fix
: fix all Prettier warnings in thesrc
directorylint
: runs ESLint on the projectcmt
: spins up thegit-cz
commit assistant
Happy coding! 🚀