Nix flake template for Node.js projects. It provides a development shell with Node.js, Corepack, Bun, Deno, and the ni package manager wrapper, plus git hooks and a flake formatter. The flake is built with purr and git-hooks.nix.
This repository is part of the develop-templates collection.
Create a project from the template:
nix flake init -t "github:nixcafe/develop-templates#node" --refreshTo use a shorter registry name:
nix registry add beans "github:nixcafe/develop-templates"
nix flake init -t beans#nodeIf you use cattery-modules, the beans registry entry already exists.
You can also create a GitHub repository from this template:
gh repo create my-node-project --template nixcafe-develop/node --cloneInitialize git if needed, enter the development shell, and set up the project:
git init && git add -A
direnv allow
# Create package.json if the project does not have one yet.
npm init -y
# Install dependencies.
ni
# Add a dependency.
ni expressni reads the lockfile to choose npm, pnpm, yarn, Bun, or Deno. If the project has no lockfile, it asks which package manager to use.
| Tool | Purpose |
|---|---|
node |
Node.js runtime from pkgs.nodejs |
corepack |
Package manager shim for pnpm and yarn |
ni, nr, nlx, nun, nci |
Commands from @antfu/ni |
bun |
Bun runtime and bundler |
deno |
Deno runtime |
nixfmt-tree |
Nix formatter exposed via nix fmt |
deadnix |
Dead Nix code linter enabled in git hooks |
statix |
Nix static analysis linter enabled in git hooks |
The shell adds node_modules/.bin to PATH when that directory exists. It also sets COREPACK_ENABLE_DOWNLOAD_PROMPT=0 and prints the Node.js version when the shell starts.
nixfmt, deadnix, and statix are enabled by default in develop/checks/git-hooks/default.nix. JavaScript and TypeScript hooks (biome, denofmt, denolint, eslint, prettier) are included as commented examples that you can uncomment:
hooks = {
nixfmt.enable = true;
deadnix.enable = true;
statix.enable = true;
biome.enable = true;
# denofmt.enable = true;
# denolint.enable = true;
# eslint.enable = true;
# prettier.enable = true;
};See git-hooks.nix for the full hook list. statix.toml holds the statix settings.
purr loads overlays from develop/overlays/ and applies them to pkgs. Create develop/overlays/node/default.nix:
final: _prev: {
nodejs = final.nodejs_22;
}The shell uses pkgs.nodejs, so the version printed at startup also changes.
Edit develop/shells/default/default.nix and add entries to packages:
packages = with pkgs; [
node
corepack
ni # @antfu/ni
bun
deno
ffmpeg
openssl
];.
├── flake.nix
├── .envrc
├── .gitignore
├── statix.toml
└── develop/
├── shells/
│ └── default/
│ └── default.nix
└── checks/
└── git-hooks/
└── default.nix
direnv allow # load the development shell
nix develop # load the shell without direnv
nix fmt # format Nix files with nixfmt-tree
nix flake check # run the flake checks, including the git hooks
ni # install dependencies
ni express # add a dependency