Building a NPM

Source: Internet
Author: User
Tags mysql create nginx reverse proxy

Building a NPM

As the online documents adopted Nodejs and CNPM version too old, including GitHub official website, there are more or less problems, eventually after tossing and finishing this document, the document database selection MySQL, the erection of Nginx proxy is not necessary.

1. Installing Nodejs

Mkdir-p/app/srccd/app/srcwget tar jxf node-v6.4.0-linux-x64.tar.xzmv node-v6.4.0-linux-x64/app/nodeuseradd Nodeecho ' Export path=/app/node/bin: $PATH ' >>/home/node/.bash_profile

2. Installing the CNPM server

Su-nodegit Clone CD CNPMJS.ORG/NPM Install

3.MySQL Create a database and authorize

CREATE DATABASE Cnpmjs; GRANT all on cnpmjs.* in [email protected] ' 127.0.0.1 ' identified by ' Password '; FLUSH privileges;

4. Database Import data

Mysql-uroot Cnpmjs < Docs/db.sql

5. Modify the configuration fileconfig/index.js

    • Enable cluster mode with options available

Enablecluster:true,
    • Port settings, registryPort for the registration service port, webPort for the Web Access port, by default

REGISTRYPORT:7001,WEBPORT:7002,
    • Administrator settings

admin: ' [email protected] ',
    • Database configuration

DB: ' Cnpmjs ', username: ' Cnpmjs ', Password: ' Password ', dialect: ' MySQL ', Host: ' 127.0.0.1 ', port:3306,
    • Binding listener address, optional. If you do not need access to this machine, add the symbolic // comment line. You can also set nginx in this machine to do reverse proxy, there is no need to modify this line.

Bindinghost: ' 127.0.0.1 ',
    • The registered hostname is modified to the corresponding IP address or domain name

Registryhost: ' npm.songsong.org ',
    • Turn on private mode, allowing only administrators to publish packages, and the default public mode allows all users to publish packages.

Enableprivate:true,
    • A naming prefix that allows a private package to be published

Scopes: [' @songsong. org '],
    • Set up a synchronization source by default

sourcenpmregistry:  ' https://registry.npm.taobao.org ', 

      Synchronous mode, none Different steps only proxy source public module, exist synchronizes only existing modules, all synchronizes all modules.

Syncmodel: ' Exist ',

6. Start the CNPM service

Bin/nodejsctl start

7. Add Nginx reverse proxy, use two domain name to differentiate CNPM Web service and registration service, overload configuration

    • Web Services

upstream npm.songsong.org{    server 127.0.0.1:7002 weight=10;} server{    listen       80;     server_name  npm.songsong.org;    index         index.html;    location /    {         proxy_redirect off;        proxy_ set_header host  $host;        proxy_set_header  x-real-ip  $remote _addr;        proxy_set_header remote-host   $remote _addr;        proxy_set_header x-forwarded-for  $proxy _add_x_forwarded_for;        proxy_connect_timeout 60;         proxy_send_timeout 60;        proxy_read_timeout 60;         proxy_pass     }}

      Registration service

upstream reg.songsong.org{    server 127.0.0.1:7001 weight=10;} server{    listen       80;     server_name  reg.songsong.org;    index         index.html;    location /    {         proxy_redirect off;        proxy_ set_header host  $host;        proxy_set_header  x-real-ip  $remote _addr;        proxy_set_header remote-host   $remote _addr;        proxy_set_header x-forwarded-for  $proxy _add_x_forwarded_for;        proxy_connect_timeout 60;         proxy_send_timeout 60;        proxy_read_timeout 60;         proxy_pass     }}

8. Installing the CNPM Client

NPM install-g CNPM

9. Set the CNPM client access, the same effect in both ways

    • Command line

CNPM Set Registry http://reg.songsong.org
    • Modifying a configuration file~/.cnpmrc

registry=http://reg.songsong.org


This article is from the "Pine" blog, be sure to keep this source http://dongsong.blog.51cto.com/916653/1850814

Building a NPM

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.