Node#
The Node provider supports NPM, Yarn, Yarn 2, PNPM and Bun.
Environment Variables#
The Node provider sets the following environment variables:
CI=trueNODE_ENV=productionNPM_CONFIG_PRODUCTION=false: Ensure that dev deps are always installedNIXPACKS_MOON_APP_NAME: Provide a name of the app you want to build from your moon repo.NIXPACKS_NX_APP_NAME: Provide a name of the NX app you want to build from your NX MonorepoNIXPACKS_TURBO_APP_NAME: Provide the name of the app you want to build from your Turborepo, if there is nostartpipeline.
Setup#
The following major versions are available
1618(Default)202223
The version can be overridden by
- Setting the
NIXPACKS_NODE_VERSIONenvironment variable - Specifying the
engines.nodefield inpackage.json - Creating a
.nvmrcfile in your project and specify the version or alias (lts/*)
Only a major version can be specified. For example, 18.x or 20.
Node Canvas
If node-canvas is found in the package.json file, then the libuuid and libGL libraries are made available in the environment.
Install#
All dependencies found in package.json are installed with either NPM, Yarn, PNPM, or Bun (depending on packageManager field in package.json if present, or the detected lockfile).
Build#
The build script found in package.json if it exists.
Or, if it's an NX Monorepo (detected if
nx.jsonexists), thebuildpipeline for theNIXPACKS_NX_APP_NAMEapp will be called. Otherwise, it will run build for thedefault_projectinnx.json. The build command is(npm|pnpm|yarn|bun) run build <NxAppName>:build:production.Or, if it's a Turborepo monorepo (detected if
turbo.jsonexists), thebuildpipeline will be called (if it exists). Otherwise, thebuildscript of thepackage.jsonreferenced byNIXPACKS_TURBO_APP_NAMEwill be called, ifNIXPACKS_TURBO_APP_NAMEis provided. Otherwise, it will fall back to the build script found inpackage.jsonat the monorepos root.Or, if it's a moon repo (detected if
.moon/workspace.ymlexists), thebuildtask for theNIXPACKS_MOON_APP_NAMEwill be called. The task name can be customized withNIXPACKS_MOON_BUILD_TASK. This will run the commandmoon run <app_name>:<build_task>.
Start#
The start command priority is:
- If it's a moon repo
- It will use
NIXPACKS_MOON_APP_NAMEfor the app name if provided, otherwise falls through to the next step. - It will use
NIXPACKS_MOON_BUILD_TASKorbuildfor the task to run.
- It will use
- If it's an NX Monorepo
- It will use
NIXPACKS_NX_APP_NAMEfor the app name if provided, otherwise it will use thedefault_projectfromnx.json - If the app has a
starttargetnpx nx run <appName>:start:productionor justnpx nx run <appName>:startif no production configuration is present - If the app is a NextJS project:
npm run start - If
targets.build.options.mainexists in the appsProject.json:node <outputPath>/<mainFileName>.js(e.gnode dist/apps/my-app/main.js) - Fallback:
node <outputPath>/index.js(e.gnode dist/apps/my-app/index.js)
- It will use
- If Turborepo is detected
- If a
startpipeline exists, call that; - Otherwise, if
NIXPACKS_TURBO_APP_NAMEis provided, call thestartscript of that package; - Otherwise, run
npx turbo run start, which will simply run allstartscripts in the monorepo in parallel.
- If a
- Start script in
package.json - Main file
index.js
Caching#
These directories are cached between builds
- Install: Global NPM/Yarn/PNPM cache directories
- Install (if Cypress detected):
~/.cache/Cypress - Build:
node_modules/.cache - Build (if NextJS detected):
.next/cache - Build (if its a moon repo):
.moon/cache - Build (if its an NX Monorepo):
<outputPathForApp>
Custom cache directories#
You can specify cacheDirectories in package.json. Each directory that is provided in that field will be added to the build-time cache.
Corepack#
Nixpacks has first class support for Corepack, an experimental tool that enables installing specific versions of Node based package managers.
For example, To install the latest version of PNPM, add a packageManager key to your package.json file
{
"packageManager": "pnpm@latest"
}
Corepack will only be used on Node 16 and above.
Bun Support#
We support Bun as a stable package manager and runtime.
SPA Application Support#
If we detect your application is using Vite and doesn't have a server, we will automatically compile your app and run it using Caddy
If you wish to turn off Caddy, you can set the environment variable NIXPACKS_SPA_CADDY to false.
If you have an application that doesn't pass the requirements for automatically using Caddy, set the NIXPACKS_SPA_OUT_DIR variable to the out directory of your application.
Caddy requirements#
If your package.json has vite any of the following dependencies:
reactreact-router(but not in framework mode)vuesvelte(but not@sveltejs/kit)preactlitsolid-js@builder.io/qwik