Environment
This section will show you how to configure your shell environment on nix-like systems (Linux, macOS) to allow you to invoke not just nr
, but any project-local Node executable directly from the command line while in the project directory.
To accomplish this, you will need to make a modification to the $PATH
environment variable in your shell's startup script. This is typically a file like ~/.bashrc
or ~/.zshrc
. The file name will vary depending on what shell you use, but the concept will be the same.
Open this file in an editor and add the following line at a place of your choosing:
This will append the local ./node_modules/.bin
folder to the list of paths that your shell will check when looking for an executable.
It might be tempting to prepend the NPM bin path to your $PATH
to guarantee a "local first" priority when resolving executables. However, this would allow a malicious package to declare binaries that shadow system-level utilities (ie: ssh
) which is a serious security risk. Instead, try to minimize the number of global NPM packages installed on your system.
Save this file and open a new terminal, where these changes will be applied.
Now, you should be able to invoke the CLI of any Node packages you have installed in a project directly from the command line.
To verify that your shell is using the local version, you can use the which
utility:
If for any reason you don't want to modify your $PATH
., you can still install nr
locally and invoke it using npx nr
. For more information, refer to the npx documentation.
Last updated