npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

n-wrap

v1.0.1

Published

Node wrapper for the n binary manager

Downloads

25

Readme

Build Status downloads npm Code Climate Test Coverage dependencies

n-wrap

Node wrapper for the n binary manager

Installation

npm install --save n-wrap

Summary

I prefer n to nvm for managing node versions, but there's no good node api for it, so I wrote this as a wrapper for the binary. It works either synchronously or asynchronously and implements all of n's currect functionality (@v2.1.0). All the functions look basically just like the CLI commands, so it shouldn't be much of a leap to figure out how things work. With all of these functions, pass a callback as the final argument to use async. All functions return (a cleaned up version of) stdout (or pass it via callback), which is probably not that useful in most cases, but if you need/want it, it's there. The async implementations follow the standard node async signature of err, results, so if an error occurs, look for it as the first argument. The synchronous implementation will throw the error, so wrap your synchronous executions in a try/catch block.

You can pass any command line flags as camel cased names as the last argument (before the callback). See opted for more on formatting these flags.

Note: This library uses the spawn-sync module which is a polyfill for child_process.spawnSync that uses thread-sleep, which means that it may not work (or work efficiently) on every platform. If you're in doubt, just use the asynchronous verion.

Usage

var n = require('n-wrap');

API

n

Invoke n with a version to install or switch to that version. These are passed directly to the command line, so things like latest, lts, etc. will still work.

var stdout = n('4.2.4');
n('4.2.4', function(err, stdout) {

});

Download, but don't install, the latest version.

var stdout = n('latest', { download: true });
n('latest', { d: true }, function(err, stdout) {

});

Or override the system architecture.

var stdout = n('stable', { a: 'x86' });
n('stable', { arch: 'x86' }, function(err, stdout) {

});

remove/rm

Remove an install binary.

var stdout = n.remove('4.0.0');
n.remove('4.0.0', function(err, stdout) {

});

bin/which

Get the path to a binary

var stdout = n.bin('4.2.4');
n.bin('4.2.4', function(err, path) {

});

use/as

Invoke the node REPL or a node script with a particular binary. Use accepts additional arguments as an array as the second parameter (these are the arguments run under the version specified).

var stdout = n.use('4.2.4', ['foo.js', '--blah'])
n.use('4.2.4', ['node_modules/.bin/mocha', '--debug'], function(err, stdout) {

});

list/ls

List available node versions (returns an array of version strings).

var list = n.list();
n.list(function(err, list) {

});

io.js

In addition to all these commands, the n object has an io property with all the same functions that run against io.js. This is similiar to running n io 1.2.3 or n io use 2.0.0. io is prefixed to the arg list so that the command operates only on io.js binaries.

var stdout = n.io('2.0.0');
n.io('2.0.0', function(err, stdout) {

});
var stdout = n.io.use('3.0.0', ['./bar.js']);
n.io.use('3.0.0', ['./bar.js'], function(err, stdout) {

});

Contributing

Please see the contribution guidelines.