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

相关文章
相关标签/搜索