Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Setting up local-npm as a launch daemon on OS X and Ubuntu.

Setting up local-npm on OS X and Ubuntu

These instructions will set up local-npm so that it runs as a launch daemon, meaning that it will start up whenever you log in.

Install local-npm

First, install local-npm and pm2:

npm install -g local-npm
npm install -g pm2

Then choose a directory to store all the local-npm data:

mkdir ~/.local-npm

Create startup script

Create a run script and save it as ~/.local-npm/ I also use nvm to choose my Node version:

#!/usr/bin/env bash

export PATH=$PATH:/usr/local/bin

# optional: set up nvm
export NVM_DIR="/Users/YOUR_USERNAME/.nvm"
if [ -s "$NVM_DIR/" ] && . "$NVM_DIR/"; then  # This loads nvm
  nvm use 4.0.0

pm2 start -s `which local-npm`

Make it runnable: chmod a+x ~/.local-npm/

OS X Only

Next, make a plist file and save it as ~/Library/LaunchAgents/com.nolanlawson.localnpm.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "">
<plist version="1.0">

Make sure to replace YOUR_USERNAME above with your username.

Now, restart your machine or run:

launchctl load -w ~/Library/LaunchAgents/com.nolanlawson.localnpm.plist

Ubuntu only

Add startup script to ~/.profile

echo "~/.local-npm/" >> ~/.profile

Set npm registery

Now just set npm to use your local-npm registry:

npm set registry

Or you can use npmrc to manage this.

Browse local-npm

A handy extra that comes with local-npm's server setup is a simple in-browser UI for browsing local modules and searching for them. You can access this at http://localhost:5080/_browse.

You can see the local-npm logs by running:

pm2 logs

You can also see the PouchDB Server Fauxton UI at http://localhost:16984/_utils, which is pretty fun.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment