nodejitsu推出私有npm倉庫託管服務

基於以下理由,企業須要私有的npm倉庫。node

  • 確保npm服務快速、穩定:對於企業來講,上線生產系統的時候,須要花半小時甚至更久等待npm模塊依賴安裝完畢,是不可接受的。部署鏡像後,能夠確保高速、穩定的npm服務。
  • 發佈私有模塊:官方的npm上的模塊所有是開源的。一些與企業業務邏輯相關的模塊可能不適合開源。這部分私有的模塊放在私有NPM倉庫中,使用起來各類方便。
  • 控制npm模塊質量和安全:npm上的模塊質量良莠不齊,搭建私有倉庫,能夠更嚴格地控制模塊的質量和安全,只有通過審覈的模塊才容許被加入私有倉庫。

然而,架設私有npm倉庫並不容易,須要耗費大量精力。最近nodejitsu 開始私有npm倉庫託管服務,從$100/月起步,按照託管的包數量收費。git

使用

使用nodejitsu的服務很簡單,註冊以後修改npm配置便可:github

npm config set registry "http://[your-subdomain].registry.nodejitsu.com"

你能夠訪問 http://[your-subdomain].registry.nodejitsu.com/manage 設定權限控制。npm

nodejitsu

注意,私有倉庫中沒有的公開的模塊,會經過代理的方式訪問公開倉庫,十分智能。segmentfault

smart-private-npm

若是你打算自行架設npm私有倉庫,能夠使用nodejitsu開源出來的smart-private-npm,這樣的話你只需將私有的模塊放在私有倉庫中,公開的模塊能夠經過代理訪問公開倉庫。安全

var smartPrivateNpm = require("smart-private-npm"),
    url = require("url");

//
// Configure your private npm. You could load this in from a file
// somewhere.
//
var config = {
  rewrites: require("./config/rewrites"),
  proxy: {
    //
    // Location of the target public npm registry. 
    //
    npm: url.parse("http://user:pass@registry.nodejitsu.com"),
    //
    // Private npm options.
    //
    policy: {
      npm: url.parse("http://user:pass@private.registry.nodejitsu.com"),
      private: {
        //
        // This is the list of 'known private modules'
        // that will always be proxied to the private npm.
        // It is built over time by remembering 'publish' requests.
        //
      },
      blacklist: {
        //
        // This is the list of modules that will ALWAYS be proxies
        // to the private npm, no matter what.
        //
      },
      whitelist: {
        //
        // If enabled: only requests for these modules will be served
        // by the proxy (unless they are 'known private modules').
        //
      },
      //
      // In 'transparent mode' the proxy will always forward to
      // the public registry.
      //
      transparent: false
    }
  },
  //
  // Server options (from 'create-servers')
  //
  http: 80
  https: {
    port: 443,
    root: "/path/to/your/ssl/files",
    key: "your-ssl.key",  // or .pem
    key: "your-ssl.cert", // or .pem
  }
};

smartPrivateNpm.createServer(config, function (err, servers) {
  if (err) {
    console.log("Error starting private npm: %j", servers);
    return process.exit(1);
  }

  console.log("Private npm running on %j servers.", Object.keys(servers));
});

架設好服務後,能夠經過以下方式發佈私有模塊:less

npm publish some-private-code --reg http://localhost/

除了nodejitsu以外,架設私有倉庫還能夠考慮阿里開源的cnpm方案。dom


撰文 SegmentFaultui

相關文章
相關標籤/搜索