Skip to content
Jacob Groundwater edited this page Jun 19, 2014 · 4 revisions

The npkg command is the one command to rule them all. It's mostly a convenience. We want a single command for

  1. installing and removing commands
  2. installing and removing services
  3. starting and stopping services
  4. configuring services

These are reflected in the commands

npkg [install|uninstall] <PKG>
npkg [start|stop] <PKG>
npkg config

installing packages

Packages installed with npkg install are installed to $HOME/lib/node_modules, and any executables defined in the package are linked into $HOME/bin. Since npkg always writes to your home directory, you do not need root permissions.

You can use npkg install to craft a custom command line interface unique to every user. For example:

Install a package from npm which includes a bin key.

$ npkg install bin-ifconfig
  --> installing bin-ifconfig from npmjs.org
  --> linked executable `ifconfig`

Executables are installed to $HOME/bin, and should be immediately available to the CLI.

$ ifconfig
{
  "lo0": { ip: "127.0.0.1", mask: "255.255.255.0" }
}

staring services

Packages installed with npkg install can also be services. A module defines a service by specifying a scripts:start key in it's package.json file.

{
  "name": "my_app",
  "scripts": {
    "start": "node server.js"
  }
}

You can one-step daemonize this module with

$ npkg start my_app

Once started with npkg the server is running in the background. You can detach from the current login session without interrupting the server.

Started services can be stopped with

$ npkg stop my_app