Giter VIP home page Giter VIP logo

run-node's Introduction

run-node Build Status

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. 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

$ npm install --save run-node

Usage

$ ./node_modules/.bin/run-node file.js

Or in an npm run script:

{
	"start": "run-node file.js"
}

Manually

Install

Download the run-node file:

$ curl -sSLO https://github.com/sindresorhus/run-node/raw/master/run-node && chmod +x run-node

Usage

./run-node file.js

Customizable cache path and error message

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"

Created by

License

MIT © Sindre Sorhus

run-node's People

Contributors

sindresorhus avatar nmssilva avatar mafredri avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.