Git Product home page Git Product logo

nvmw's Introduction

nvmw

nvmw - the nvm wrapper.

Ensure that a specified version of nvm is installed, and then use it to ensure a specific version of nodejs is installed. Then execute the given arguments with the desired node version selected (i.e., following an nvm use).

Specify the node version to install in a .nvmrc file, as usual with nvm, or alternatively with the NODE_VERSION environment variable (which supercedes any .nvmrc file).

You can also specify which version of nvm to use, with the NVM_VERSION env var. Otherwise, a default value is used (hard-coded below). This should be a specific version tagged version, excluding the leading 'v'.

For status messages, set the NVMW_DEBUG variable to "1".

Everything is stored in the .nvmw directory in the same directory as this script is located (NOT necessarily the working directory). Versions of the nvm.sh script are stored under there, and, when invoked through the nvm-wrapper, is configured to use .nvmw/nvm as the NVM directory; all versions of node and related tools (e.g., npm), plus all "globally" installed npm modules are stored there (assuming you use the nvm-wrapper to install them, like ./nvmw npm install MODULE_NAME -g). If you want, you can change the location where nvmw stores things by setting the NVMW_DIR env var. For instance, you could set it to a system wide location so that nvmw and nvm cache everything in one location.

Installation

Just drop nvmw into your project's root directory. That's it. Oh, and you need either curl or wget installed. Other than that, it should work in pretty much any bash shell (possibly others).

E.g.:

wget https://raw.githubusercontent.com/mearns/nvmw/v1.0.0/nvmw

Demo

$ pwd
/tmp
$
$ # Make sure no previous nvmw things are in the way,
$ # to get consistent output.
$ rm -rf .nvmw
$ rm -f .nvmrc
$
$ # Specify which version of node we want to use, in the .nvmrc
$ echo "4.3.1" > .nvmrc
$
$ # Invoke node, using the wrapper.
$ # Neither nvm nor node is installed here yet, so they will both be installed first.
$ ./nvmw node --version
######################################################################## 100.0%
Found '/tmp/.nvmrc' with version <4.3.1>
Downloading https://nodejs.org/dist/v4.3.1/node-v4.3.1-linux-x64.tar.xz...
######################################################################## 100.0%
Now using node v4.3.1 (npm v2.14.12)
Creating default alias: default -> 4.3.1 (-> v4.3.1)
v4.3.1
$
$ # The version is installed now, it'll be quicker this time.
$ ./nvmw node --version
v4.3.1
$
$ # Override the version with the NODE_VERSION env var.
$ # The new version of node will be installed, but nvm is already installed.
$ NODE_VERSION=5.6.0 ./nvmw node --version
######################################################################## 100.0%
Now using node v5.6.0 (npm v3.6.0)
v5.6.0
$
$ # Back to using nvmrc
$ ./nvmw node --version
v4.3.1
$
$ # And back to overridden version
$ NODE_VERSION=5.6.0 ./nvmw node --version
v5.6.0
$
$ # Install npm modules.
$ sudo ./nvmw npm install pm2 -g
npm WARN optional dep failed, continuing [email protected]
/tmp/.nvmw/nvm/versions/node/v4.3.1/bin/pm2 -> /tmp/.nvmw/nvm/versions/node/v4.3.1/lib/node_modules/pm2/bin/pm2
/tmp/.nvmw/nvm/versions/node/v4.3.1/bin/pm2-dev -> /tmp/.nvmw/nvm/versions/node/v4.3.1/lib/node_modules/pm2/bin/pm2-dev
[email protected] /tmp/.nvmw/nvm/versions/node/v4.3.1/lib/node_modules/pm2
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
├── [email protected]
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected]
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected]
└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
$
$ # Now pm2 is installed, but only for the local version 4.3.0 of node.
$ ./nvmw pm2 --version
1.0.1
$
$ # It isn't installed for other versions of node.
$ NODE_VERSION=5.6.0 ./nvmw pm2 --version
./nvmw: line 198: pm2: command not found
$
$ ./nvmw which pm2
/tmp/.nvmw/nvm/versions/node/v4.3.1/bin/pm2

Limits

You shouldn't generally use the nvm wrapper to execute nvm. It may work in particular cases, but, in particular, if you're overriding the node version with the NODE_VERSION env var, nvm itself does not consider this.

nvmw's People

Contributors

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