nodejs-app-template v1.7.1
nodejs-app-template
This is a template for a Node.js TypeScript project.
The following following tools have been configured:
- Vitest for unit testing
- ESLint for linting
- Prettier for code formatting
- ts-node for running TypeScript scripts
- TypeScript for TypeScript support
Usage
Install dependencies
npm ci
Edit the code
You can edit the code in the src
directory.
The entry point of your application is src/main.ts
.
Run the application in development mode
npm run dev
Note: The project uses ts-node to run TypeScript code on the fly.
Compile the application
npm run compile
This will create a dist
directory with the compiled code.
Note: The dist
directory will mimic the main directory structure. All directories with TypeScript files will be recreated in the dist
directory. In the default configuration those are src
and test
.
Run the compiled application
npm run preview
To run with NODE_ENV=production
:
npm run start
Note: This will command will fail if the application has not been compiled (no dist
directory)!
Test the application
The tests can be found in the test
directory.
Vitest is used to run and write the tests.
npm run vitest:check
This will run the tests and also providing a tabular code coverage report.
An HTML code coverage report will be also generated in the coverage_report
directory.
Run the linter
npm run eslint:check
Note: The linter will return a non-zero exit code if there are any linting errors or warnings.
You can also try to automatically fix some of the errors and warnings by running:
npm run eslint:fix
Run the formatter
npm run prettier:check
Formatting errors can be automatically fixed by running:
npm run prettier:fix
CI Pipeline
The CI pipeline is configured in the .github/workflows/ci.yml
file.
It consists of the following jobs:
ESLint check
npm run eslint:check
Prettier check
npm run prettier:check
Vitest check
npm run vitest:check
You can later download the coverage report as an artifact named coverage_report
.
npm audit check
npm run npm-audit:check
TypeScript check
Check if the code compiles:
npm run typescript:check
Compiling the application
This job requires all the previous formatting-unrelated jobs to pass.
npm run compile
You can later download the compiled code as an artifact named dist
.