Node.js: Difference between revisions

DHCP (talk | contribs)
m various formatting and style improvements
Added development environment
Line 9: Line 9:


See <code>nix search nixpkgs nodejs</code> for additional versions like <code>nodejs-12_x</code>, etc.
See <code>nix search nixpkgs nodejs</code> for additional versions like <code>nodejs-12_x</code>, etc.
== Development environment ==
Also see [[Development environment with nix-shell]] on this wiki.
=== Nixpkgs example ===
<syntaxhighlight lang="nix">
# shell.nix
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
  nativeBuildInputs = with pkgs.buildPackages; [
    nodejs_22
    yarn
  ];
}
</syntaxhighlight>
=== Corepack example ===
To use specific/pinned versions of your runtime & package manager, a combination of corepack & steam-run can be used<syntaxhighlight lang="nix">
# shell.nix
{ pkgs ? import <nixpkgs> {} }:
 
pkgs.mkShell {
  buildInputs = with pkgs; [
    corepack
    steam-run-free
  ];
  shellHook = ''
    alias deno="steam-run pnpm deno"
  '';
}
</syntaxhighlight><syntaxhighlight lang="json">
// package.json
{
  "packageManager": "pnpm@11.4.0",
  "devEngines": {
    "runtime": {
      "name": "deno",
      "version": "^2.7.14",
      "onFail": "download"
    }
  }
}
</syntaxhighlight>


== Packaging ==
== Packaging ==