Lesson 09-Setting Up an npm Local Network Registry

Erlang Installation

  • Obtain the Erlang Installation Package
sudo wget http://www.rabbitmq.com/releases/erlang/erlang-18.3-1.el6.x86_64.rpm
  • CentOS RPM One-Click Installation

For CentOS, execute the command rpm -ivh erlang-18.3-1.el6.x86_64.rpm. Note that the rpm command is not supported in Ubuntu, and running it may result in the following error:

rpm: RPM should not be used directly install RPM packages, use Alien instead!
rpm: However assuming you know what you are doing...
error: Failed dependencies:
  • Solution for RPM One-Click Installation on Ubuntu
  1. Install alien with the command: sudo apt-get install alien
  2. Convert the .rpm package to .deb format: sudo alien package.rpm (replace package.rpm with your package name)
  3. Install using dpkg: sudo dpkg -i package.deb
  • Verify Installation
$ erl
Erlang/OTP 18 [erts-7.3] [source] [64-bit] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V7.3  (abort with ^G)
1>

CouchDB Installation

Execute the following commands to install CouchDB and Futon on your server:

mkdir /data
cd /data
sudo wget http://mirrors.tuna.tsinghua.edu.cn/apache/couchdb/source/2.3.1/apache-couchdb-2.3.1.tar.gz
sudo tar xfv apache-couchdb-2.3.1.tar.gz
cd apache-couchdb-2.3.1
sudo ./configure

Alternatively, for Ubuntu:

sudo apt-get install couchdb -y

CouchDB runs on port 5984 by default. Verify the installation with:

$ curl localhost:5984
{"couchdb":"Welcome","uuid":"8d11c599b6487b117e21b8d7b5f79bed","version":"1.6.0","vendor":{"version":"15.10","name":"Ubuntu"}}

Download CouchDB Source

wget http://mirrors.tuna.tsinghua.edu.cn/apache/couchdb/source/2.3.1/apache-couchdb-2.3.1.tar.gz

Accessing Futon

Futon is a WebUI interface provided by CouchDB. For secure access, you can create an SSH tunnel from your local machine to the server.

Create an SSH tunnel mapping local port 5984 to the remote server’s port 5984:

ssh -L5984:127.0.0.1:5984 qufei3@192.168.6.130

After establishing the tunnel, access Futon by navigating to http://localhost:5984/_utils/ in your browser. The interface should appear as shown below:

For additional CouchDB installation methods, refer to the official documentation.

Setting Up an npm Registry

Ensure CouchDB is installed and running before setting up the npm registry.

  1. Create a Database

This database will store module and file information.

curl -X PUT http://localhost:5984/registry
{"ok":true}
  1. Set Username and Password
curl -X PUT http://localhost:5984/_config/admins/admin -d '"123456"'
  1. Clone the npm Registry CouchApp

Clone the npm registry repository and set it up:

git clone git://github.com/npm/npm-registry-couchapp
cd npm-registry-couchapp
npm install
npm start \
  --npm-registry-couchapp:couch=http://localhost:5984/registry
npm start \
  --npm-registry-couchapp:couch=http://admin:123456@localhost:5984/registry
npm run load \
  --npm-registry-couchapp:couch=http://localhost:5984/registry
npm run copy \
  --npm-registry-couchapp:couch=http://localhost:5984/registry
  1. Configure the npm Client

Set the npm registry to use the local CouchDB instance:

npm config set \
  registry=http://localhost:5984/registry/_design/app/_rewrite
Share your love