luqin / blog

My blog
https://github.com/luqin/blog/issues
64 stars 11 forks source link

CNPM 搭建私有 NPM 服务 #3

Open luqin opened 8 years ago

luqin commented 8 years ago

参考:

当前最新版本:2.0.0-rc.15

# clone from github
$ git clone git://github.com/cnpm/cnpmjs.org.git $HOME/cnpmjs.org
$ cd $HOME/cnpmjs.org

修改配置

$ vim config/config.js
module.exports = {
  bindingHost: '127.0.0.1', // only binding on 127.0.0.1 for local access

  // input your custom config here
  admin: {
    'admin': '***'
  },

  /**
   * database config
   */

  database: {
    db: 'cnpmjs',
    username: 'postgres',
    password: '',

    // the sql dialect of the database
    // - currently supported: 'mysql', 'sqlite', 'postgres', 'mariadb'
    dialect: 'postgres',

    // custom host; default: 127.0.0.1
    host: '127.0.0.1',

    // custom port; default: 3306
    port: ***,

    // use pooling in order to reduce db connection overload and to increase speed
    // currently only for mysql and postgresql (since v1.5.0)
    pool: {
      maxConnections: 10,
      minConnections: 0,
      maxIdleTime: 30000
    },

    logging: !!process.env.SQL_DEBUG,
  },

  // registry scopes, if don't set, means do not support scopes
  scopes: ['@mycnpm']
};

安装依赖

# install dependencies
$ make install

创建数据库

# 创建数据库:cnpmjs

初始化数据库

$ node --harmony models/init_script.js 

启动服务

$ npm run start

For Windows: node --harmony dispatch.js

后台进程启动

nohup node --harmony /root/cnpmjs.org/dispatch.js > /root/cnpmjs.org/startlog.log 2>&1 &

关闭后台进程

ps -ef | grep node
kill -9 pid

检查

#open registry and web
# registry
http://myip:7001
# web
http://myip:7002

注册自启动

cd /root/cnpmjs.org/
vi start.sh

输入脚本保存:

nohup node --harmony /root/cnpmjs.org/dispatch.js > /root/cnpmjs.org/startlog.log 2>&1 &

增加软链接:

ln -s start.sh /etc/init.d/cnpm

CNPM 使用文档

CNPM 使用文档

luqin commented 8 years ago

cnpmjs.org 升级

2.0.0-rc.15 => 2.9.2

安装 nvm

https://github.com/creationix/nvm

升级 Node.js => v5.10.0

……