Template for developing Node.js projects with TypeScript.
Features:
- supports ESM and top-level
await
. - swc for faster builds and
tsconfig.paths
support. - tsx for development.
- vitest for testing.
- eslint for linting.
- prettier + lint-staged hook for code formatting.
- github actions for continuous integration.
- pre-configured Dockerfile.
- pre-configured debugger for VS code.
npm install
npm run dev
npm run dev:debug
npm run check
npm run build
Note
swc
does not check for type errors when building. If you want type checks during build, runnpm run check
in conjunction.
npm run start
npm run test
# run in watch mode.
npm run test:watch
# generate coverage report.
npm run test:coverage
npm run lint
npm run fmt
This template setting up path aliases via tsconfig.paths
. By default, a @
alias is configured, pointing to the src
directory.
If you add new aliases, these have to be mirrored in:
.swcrc {jsc.paths}
for the aliases to work in build output.vitest.config.ts {test.alias}
for the aliases to work in unit tests.
The included Dockerfile
uses a multi-stage build to reduce the size of the final container. Build dependencies are pruned. Code is executed as non-root user.
To run the container, use:
docker build -t node-ts-template .
docker run --env-file .env -p 3000:3000 node-ts-template
- Due to how ESM works, module imports from a relative path require a
.js
postfix.