MacPro using CNPMJS to build private NPM services

Source: Internet
Author: User

Objective

The previous time see NPM Private library cnpmjs.org, always want to try how to build, directly dragged to now, too lazy!

Let's briefly introduce the following cnpmjs.org:

CNPM means company NPM. According to the introduction on GitHub, the translation is probably:

Enterprise NPM Private Library and web side based on the Koa,mysql and simple Store service.

The goal is to provide a low-cost maintenance and easy-to-use solution for private npm.

With cnpmjs.org you can:

1. Build an enterprise NPM private library

2. Build a NPM image

3. Build a warehouse that is completely independent of NPM to store what you want to store

Next, let's get started!

Mac system and Software environment:
1 Mac OS X Yosemite 10.10.12 Git:mac comes with V1.9.33 xcode:6.1.1
1. Install MySQL

To the MySQL official website select the corresponding version of the download after the direct installation (with thunder download will be a bit), I installed is

Mysql-community Server (GPL) 5.6.22 Compiled for OSX10.8(x86_64),

When the installation is complete, the MySQL service starts by default.

2. (optional) Install MySQL Workbench

This step is primarily used for subsequent script initialization and password modification. When the installation is complete, open:

 

Click the New Connection button on the interface:

 

When MySQL initially uses the root user, the password is empty.
when you're done, open it and then change the root password. (e.g.).

 


For command line familiarity, this can be done with the command line.

3, Installation Nodejs

You need to install a newer version that corresponds to the CNPMJS version, or it may fail.
Open a command-line window, create a new directory to hold the Nodejs, pull node's source code from GitHub to compile the installation yourself:

1 mkdir Nodejs 2 CD Nodejs 3 git clone git://github.com/ry/node.git4CD node5 ./Configure 6  7 sudo make install

After installation, test it out:

1 node-v

Output: V0.13.0-pre

4, Installation Cnpmjs

Download source from GitHub

1 git clone git://github.com/fengmk2/cnpmjs.org.git2cd cnpm.org3 ls-l

 

There are two main files to use here:
1) Docs/db.sql

This is the database initialization script, the table used by CNPMJS is inside.
Using the workbench above to execute this script, the script executes with the following table:

2) Config/index.js

System configuration script, You can override the default configuration by creating a Config.js file, or modify Index.js directly (not recommended).

One thing to note here is that in index.js there is a configuration called bindinghost, which means the binding address on local access, and the default configuration is 127.0.0.1. That is, you can only access this address locally, if you use localhost is not accessible, with other IP is not.

Create a Config.js file

Vim./config/config.js
  The contents of the Config.js file are as follows:
1Module.exports = {2Debugfalse,// 3 database: {4DB: ' Cnpmjs ',//default is Cnpmjs_test5Host: ' 127.0.0.1 ',//default6port:3306,//default7Username: ' Root ',//default8Password: ' Your password ',//default is empty9Dialect: ' MySQL '//using MySQL, the default is SQLite, also supports POSTGRES,MARIADB, temporarily does not support OracleTen }, OneSyncmodel: ' Exist '//Synchronize existing modules, default to None, and an option of all A}

For more configuration, refer to the Index.js file under Config directory.

5. Start the service

Once the above steps are configured, you can start the CNPMJS service, for example, enter a command:

1 node--harmony_generators dispatch.js 

After starting the service, enter in the browser: http://127.0.0.1:7002, if you see the following page, it means success!

6. Client Use

The private service is set up, how to use it on the client?

The simplest way to do this is to set up NPM's registry:

1 npm confit set registry=http://192.168.1.6:7001

Of course, if you don't want to change the original registry, then add a--registry parameter after each command, for example:

NPM Install Gulp-g--registry=http://192.168.1.6:7001

for In- house developers who can't access the network directly, or set the next registry!

Another way is to use CNPMJS's client cnpm:

NPM install-g CNPM

Of course, CNPM also need to set registry.

Careful children's shoes may be found, open the Web page and registry use of the port is not the same AH! Don't worry, this is true, because CNPMJS has the default two access ports:

1) 7001 is registry port, corresponding to Registryport configuration item

2) 7002 is the Web port, corresponding to the WebPort configuration item

If you do not like the two default ports, you can modify yourself, you can look at the config/index.js configuration file, inside the comments are written very clearly.

7. Release module

for the most part, someone else has been able to write a good module, but sometimes it's not exactly what you want, or the leader wants you to write a few public modules for the project, You need to write the module yourself and publish it to a private library. CNPMJS can be used to manage well-developed modules within the company.

First add or modify the Config/index.js file in Config/config.js, and change the admin in admins to your own email address.

admins: {    admin: ' aaa@qq.com '}

After the modification is complete, restart the service. Then add the user, because only the admin user can publish, so add the Admin user:

1 npm adduser--registry=http://192.168.1.6:70012username:admin3Password: Set Password 4 Email: (This was public) email address modified above

After adding users, login:

1 NPM Login--registry=http://192.168.1.6:7001

Here will also appear and add users the same prompt as you fill in, because just added users, so directly enter with the default.

123 Email: (This was public) (your email)

Ready, let's simply write a module to test it:

1 VI testone.js
1 /* 2 * Public Module 3  */ 4 function Hello (name) {5         console.log ("Hello" + name); 6 }78 exports.hello = Hello;

Writing Package.json files

1 VI Package.json
1 {2         "name": "Testone",3         "version": "1.0.0",4         " Main ":"./testone.js ",5         " description ":" A Common Module ",6         " Author ":" Wyzfzu "7 }

Once written, you can publish:

1 npm publish--registry=http://127.0.0.1:7001

Output: [email protected]

You can also add the--verbose parameter to view a more detailed log.

Install the test, go to another directory, enter the command:

1

A few things to note:

1) Win7 command line to run with administrator privileges

2) do not store irrelevant files in the module directory

Toss for a long time, finally fix, here record. Ready to try it on CentOS.

Reference:

1, CNPM to build private NPM service

2. Use CNPM to build a private NPM warehouse inside the Enterprise

3, Mac under node JS installation

MacPro using CNPMJS to build private NPM services

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.