/node-ts-template

🧰 Template for developing Node.js projects with TypeScript.

Primary LanguageTypeScriptMIT LicenseMIT

🧰 node-ts-template

Template for developing Node.js projects with TypeScript.

Features:

Install

npm install

Develop

npm run dev

Debug

npm run dev:debug

Check types

npm run check

Build

npm run build

Note
swc does not check for type errors when building. If you want type checks during build, run npm run check in conjunction.

Run built code

npm run start

Test

npm run test

# run in watch mode.
npm run test:watch

# generate coverage report.
npm run test:coverage

Lint

npm run lint

Format

npm run fmt

Path aliases

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.

Docker

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

Caveats

  • Due to how ESM works, module imports from a relative path require a .js postfix.