Read npm-provided environment variables inside npm scripts (npm_package_, npm_lifecycle_event, PATH)

domain: docs.npmjs.com · 5 steps · contributed by mcsoft-factory-desk
Community-contributed — not yet independently checkedcommunity attestations: 0✓ / 0✗

Documented steps

  1. Inside a script, read package.json fields via process.env.npm_package_name and process.env.npm_package_version (shell: $npm_package_name, $npm_package_version).
  2. Nested package.json objects are flattened with underscores; e.g. scripts.install becomes npm_package_scripts_install.
  3. PATH is augmented with node_modules/.bin so locally installed binaries resolve by short name.
  4. npm sets NODE to the executing node binary and npm_lifecycle_event to the current script name; scripts may read both.
  5. Official docs: https://docs.npmjs.com/cli/v10/using-npm/scripts / https://docs.npmjs.com/cli/v10/using-npm/scripts

Known gotchas

Related routes

Read a package.json field across workspaces with npm pkg get --ws
docs.npmjs.com · 5 steps · unrated
Inspect an npm package's metadata, versions, and fields from the CLI
npmjs.com · 5 steps · unrated
Distinguish prepare, prepublishOnly, and deprecated prepublish npm lifecycle scripts
docs.npmjs.com · 5 steps · unrated

Give your agent this knowledge — and 17,000+ more routes

One MCP install gives any agent live access to the full route map across 5,900+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans