
Its top level looks like this: npm_package_json: '/Users/robin/new-package/package.json', The prefix npm_package_ gives us access to the contents of package.json. Npm_config_userconfig: '/Users/robin/.npmrc', Npm_config_user_agent: 'npm/8.15.0 node/v18.7.0 darwin arm64 workspaces/false', Npm_config_local_prefix: '/Users/robin/new-package', Npm_config_globalconfig: '/usr/local/etc/npmrc', These are a few examples: npm_config_cache: '/Users/robin/.npm', Under prefix npm_config_, we can see some of npm’s configuration settings ( which are described in the npm documentation). On Windows, npm_lifecycle_script would SET in this case. Under npm_lifecycle_, we find the name and the definition of the currently running package script: npm_lifecycle_event: 'env', The npm_ variables have a hierarchical structure. Let’s only print those, in alphabetical order: npm run env | grep npm_ | sort The names of all of npm’s temporary variables start with npm_. Npm package scripts are defined via property "scripts" of package.json: Defining operating-system-specific scripts.per-env: switching between scripts, depending on $NODE_ENV.Expanding the capabilities of package scripts.Putting files or directories into the trash.Running multiple scripts concurrently or sequentially.Running package scripts from a command line.Running bin scripts and package-internal modules.Piping and redirecting input and output.Output of life cycle scripts that run during npm install.Log levels and information written to the npm log.


Log levels and information printed to the terminal.The npm log level (how much output is produced).Getting and setting environment variables.Using environment variables in package scripts.The shell environment in which package scripts are run.Getting tab completion for package scripts on Unix.Preventing package scripts from being run automatically.Which shell is used to run package scripts?.Shorter npm commands for running package scripts.In this blog post, we explore how that works and how we can write them in a way that works across platforms (Unixes and Windows). The npm package manager lets us define small shell scripts for tasks and execute them via npm run.
