A sane, opinionated template for esm nestjs projects written in typescript that doesn't rely on transpilation - typescript is ran directly by node (currently using tsx loader while decorators aren't part of v8).
Important
This template requires mise. It manages the correct versions of runtimes and tooling, such as Node itself, pnpm, and others.
It is also the task manager for the project, so no package.json scripts.
Check https://mise.jdx.dev for more details on mise, and the tasks section below (or the .mise.toml file) for the available tasks.
Uses, among other tools/packages:
- pnpm as package manager for node
- biome for code linting and formatting
- lefthook for git hooks
- cocogitto for commit message linting
- vitest for testing
- tsx for dev time typescript
To ensure a reproducible environment, mise is used:
- Install mise: https://mise.jdx.dev/getting-started.html#installing-mise-cli
- Activate mise: https://mise.jdx.dev/getting-started.html#activate-mise
- Run setup:
mise setup
This task trusts the project config, installs CLI tools (Node, pnpm, ncu), and runs pnpm install. All other scripts are standard package.json commands.
Note
Git hooks are in place to make sure both the tooling managed by mise and the project dependencies are synced with each checkout and merge.
- esm
- biome is objectively faster and overall a better choice over eslint+prettier
- no weird build-then-run-dev flow, node (with tsx loader) runs the code
- people still using jest should... reconsider
- any kind of code generation is ass, but nestjs's cli is particularly terrible, so dependencies for that and the nest-cli.json file are gone - just add files yourself, I promise you'll be fine
- the result pattern is used with the @mkvlrn/result package - together with the global filter, error handling becomes a breeze; it is of course optional, but I think it's a good idea to just use it everywhere
- overall it's just as opinionated, but a tad cleaner, stricter, and modernized
Just check what is in it, it't not that different from what you'd get with nestjs-cli.
Subpath imports (#/) are used instead of relative paths, mapped in both package.json and tsconfig.json.
Example:
import { add } from "#/math/basic"; // this points to ./src/math/basic.tsRuns the project in watch mode.
Runs the project.
Runs tests.
Runs biome in fix mode to lint and format the project.
Runs type checking using tsc.
This repository uses GitHub Actions for CI. The workflow is defined in .github/workflows/checks.yml.
It automates:
- Linting & Formatting: Running Biome.
- Type Checking: Running TypeScript type checking.
- Testing: Running Vitest with code coverage (generated by Istanbul).
You might want to install the recommended extensions in vscode. Search for @recommended in the extensions tab, they'll show up as "workspace recommendations".
If you have been using eslint and prettier and their extensions, you might want to disable eslint entirely and keep prettier as the formatter only for certain types of files.
This is done by the .vscode/settings.json file.
Debug configuration is also included for running the source directly with node.
MIT