Security News
The Dark Side of Open Source
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
run-node
Advanced tools
Readme
Run the Node.js binary no matter what
You can't always assume running $ node file.js
will just work. The user might have the node
binary in a non-standard location. They might be using a Node.js version manager like nvm
, which is sourced in a subshell and not available from the outside. Or they might have node
installed as a local dependency in an npm project. It also depends from where you're trying to run it. For example, GUI apps on macOS doesn't inherit the $PATH
, so the node
binary would not be found. Most projects that depend on Node.js just end up telling the user to manually set the full path to the node
binary in some project specific settings. Now every project has to do this. Ugh... I prefer things to just work. With this module it will.
This Bash script uses some tricks to find the Node.js binary on your system and run it.
Can be used from any environment that can spawn a process (Shell, Python, Ruby, Swift, Objective-C, etc).
$ npm install run-node
$ ./node_modules/.bin/run-node file.js
Or in an npm run script:
{
"start": "run-node file.js"
}
If the node
package is found in the local node_modules
directory (for instance, if you have it installed as a devDependency of your npm project), this is the node
binary that will be used.
Download the run-node file:
$ curl -sSLO https://github.com/sindresorhus/run-node/raw/master/run-node && chmod +x run-node
./run-node file.js
The cache path and error message are defined by the RUN_NODE_CACHE_PATH
and RUN_NODE_ERROR_MSG
environment variables. You could use them in a script or add them to your ~.bashrc
.
Default config:
export RUN_NODE_ERROR_MSG="Couldn't find the Node.js binary. Ensure you have Node.js installed. Open an issue on https://github.com/sindresorhus/run-node"
export RUN_NODE_CACHE_PATH="/home/username/.node_path"
If the RUN_NODE_CACHE_PATH
environment variable is defined explicitly, the script it points to will be sourced before looking for a node
binary. You can use this script to override your PATH
variable so that a specific node
binary is found.
FAQs
Run the Node.js binary no matter what
The npm package run-node receives a total of 543,602 weekly downloads. As such, run-node popularity was classified as popular.
We found that run-node demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
Research
Security News
The Socket Research team found this npm package includes code for collecting sensitive developer information, including your operating system username, Git username, and Git email.
Security News
OpenJS is warning of social engineering takeovers targeting open source projects after receiving a credible attempt on the foundation.