Code Monkey home page Code Monkey logo

nvmjs's Introduction

Node Version Mananger (JS wrapper for nvm)

NPM Version NPM Downloads test js-standard-style

A wrapper around nvm with to interact via a JavaScript interface.

NOTE: This is a WIP, contributions are welcome so please open PRs if your feature is not implemented yet.

Usage

$ npm i nvmjs
const { NVM } = require('nvmjs')

const nvm = new NVM({
  // For now only works with this fork, pending some PRs
  // Thsese will be default until then
  nvmInstallSrc: 'https://raw.githubusercontent.com/wesleytodd/nvm/wip/install.sh',
  nvmSrc: 'https://github.com/wesleytodd/nvm.git',

  nvmDirectory: process.env.NVM_DIR,
  nvmSearchDirectories: [
    // Checks this first if passed
    // opts.nvmDirectory,

    // If globally installed, will use it
    // process.env.NVM_DIR,

    // Checks this last (will install inside the module dir)
    // path.join(__dirname, .nvm)
  ],
  env: {
    // Set env vars to be used when calling nvm
  }
})

// Install nvm to opts.nvmDirectory
const [dir, ver] = await nvm.installNvm()

// Find installs based on opts.nvmSearchDirectories
const [dir, ver] = await nvm.findExistingNvm()

// Install a node versions, defaults to lts_active
const ver = await nvm.install(/* version: 14, 14.0.0, lts_active */)
console.log(ver)
/*
{
  exitCode: 0,
  stdout: '...',
  stderr: '...',
  node: {
    path: '~/.nvm/versions/node/v14.1.0/bin/node',
    version: '14.1.0',
    major: 14,
    minor: 1,
    patch: 0
  },
  npm: {
    version: '6.14.4',
    major: 6,
    minor: 14,
    patch: 4
  }
}
*/

// Run with nvm
const { stdout } = await nvm.run(['-e', 'console.log(process.version)'], {
  // Surpress nvm output
  silent: true,
  version: '14' // accepts all aliases
})

// Exec with nvm
const { stdout } = await nvm.exec(['node', '-e', 'console.log(process.version)'], {
  // Surpress nvm output
  silent: true,
  version: '14' // accepts all aliases
})

//
// Other helper methods
//

// which node version, returns path to node
await nvm.which(/* optional version */)

// Return current node version
await nvm.current()

// Return version of nvm
await nvm.version()

// Run arbitrary nvm command
await nvm.nvm(['ls'])
await nvm.nvm(['use', '14'])
await nvm.nvm(['cache', 'dir'])

nvmjs's People

Contributors

wesleytodd avatar noahhahm avatar

Stargazers

Harry Hopkinson avatar  avatar

Watchers

Jordan Harband avatar James Cloos avatar  avatar  avatar

Forkers

noahhahm

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.