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

npm-runner

v0.1.4

Published

runs npm commands via npm's CLI or JS API, at your choice

Downloads

5

Readme

npm-runner

runs npm commands via npm's CLI or JS API, at your choice

NPM

installation

to get all capabilities, and choose the API implementation at runtime:

npm i npm-runner

to only use the CLI API:

npm i npm-runner --no-optional

API

init([globalOptions])

initializes an npm-runner implementation and returns a runner function to call with npm commands.

globalOptions {Options} (optional) global options that will be applied by default on every invocation of the runner.

Returns: {Function} a run() function that is bound to the passed options.

run(command, [localOptions], callback)

invokes an npm command. available only after initialization.

command {String} an npm command to run, e.g. install -D.
localOptions {Options} (optional) local options that will be applied to the current invocation only, and override the global options passed on init().
callback {Function} a callback that will be called when the npm command execution is finished. it receives two arguments: err and output. err is any raised error, and output is the command output, broken down to an array of output lines.

Options

Type: Object<*>

instructions to apply globally (when passed to init()), or for a specific npm invocation (when passed to run()).

api

Type: String
Default value: 'cli'
Mandatory: no

how commands will be executed: 'javascript' means using the npm node module javascript API (requires npm as a local npm dependency), while 'cli' will rely on your global npm installation and send commands to the terminal.

tee

Type: Boolean
Default value: false
Mandatory: no

whether to pipe the npm command output to stdout (in any case, the output will be sent to the run() callback).

cwd

Type: String|Path
Default value: ''
Mandatory: no

the directory to execute the npm command from (at the moment it's only used by the CLI API).

ignoreErrors

Type: Array<String>
Default value: []
Mandatory: no

don't fail the execution when any of these terms are found in error messages of the npm command output.

globalFlags (TBD)

Type: Array<String>
Default value: []
Mandatory: no

npm flags that will be appended to every command. e.g. put 'parseable' here if you intend to dissect the output of every command, or 'json' if you always want to use the command output as an object.

examples

use global options

const npm = require('npm-runner').init({
    tee: true
});

npm('update', done);

use command options

const npm = require('npm-runner').init();

npm('link npm-runner', {
    cwd: path.resolve(__dirname)
}, done);

switch APIs

const npm = require('npm-runner').init({
    api: 'javascript'
});

npm('update', done);

npm('update', {
    api: 'cli'
}, done);

ignore errors from the command stderr

here, the done callback will be called with no errors, even if some extraneous errors slipped to the stderr.

const npm = require('npm-runner').init({
    ignoreErrors: [
        'extraneous'
    ]
});

npm('list', done);

use parseable output to get the local path of an npm module

const npm = require('npm-runner').init();
const packageName = 'npm-runner';

npm(`list ${packageName} --parseable --long --silent`, (err, parseableOutput) => {
    let output = parseableOutput.shift();
    if (output) {
        let path = output.split(':').shift();
        console.log(`${packageName}'s path is "${path}"`);
    }
});