Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # ================================
- # Install cnpmjs.org and dependencies
- $ npm install -g --build-from-source \
- --registry=https://registry.npm.taobao.org \
- --disturl=https://npm.taobao.org/mirrors/node \
- cnpmjs.org cnpm sqlite3
- # ================================
- # Start local cnpmjs.org
- $ nohup cnpmjs.org start --admins='myname' \
- --scopes='@my-company-name'
- # ================================
- # Login (and create account) to my private registry using admin account
- $ npm login --registry http://127.0.0.1:7001 --scope=@my-company-name
- Username: myname
- Password:
- Email: (this IS public) myname@example.com
- Logged in as myname to scope @my-company-name on http://127.0.0.1:7001/.
- # ================================
- # Let's see what happened to .npmrc
- $ cat ~/.npmrc
- xxxxxxxxx
- @my-company-name:registry=http://127.0.0.1:7001/
- //127.0.0.1:7001/:_password="xxxxxxxxx"
- //127.0.0.1:7001/:username=myname
- //127.0.0.1:7001/:email=myname@example.com
- //127.0.0.1:7001/:always-auth=false
- # ================================
- # Let's upload a private package
- $ mkdir example_private_module && cd example_private_module
- $ npm init
- $ cat package.json
- {
- "name": "@my-company-name/example_private_module",
- "version": "1.0.0",
- "description": "",
- "main": "index.js",
- "scripts": {
- "test": "echo \"Error: no test specified\" && exit 1"
- },
- "author": "",
- "license": "ISC"
- }
- $ echo "module.exports = 'hello';" > index.js
- # ================================
- # Publish the private package to our private registry
- $ npm publish
- + @my-company-name/example_private_module@1.0.0
- # ================================
- # Now let's use this private package in a project
- $ cd .. && mkdir example_project && cd example_project
- $ npm install optimist @my-company-name/example_private_module
- /Users/Breezewish/Desktop/cnpm/example_project
- ├── @my-company-name/example_private_module@1.0.0
- └─┬ optimist@0.6.1
- ├── minimist@0.0.10
- └── wordwrap@0.0.3
- # ================================
- # cnpm will not success, because cnpm use a different npmrc
- $ cnpm install optimist @my-company-name/example_private_module
- npm ERR! Darwin 14.5.0
- npm ERR! argv "/usr/local/Cellar/node/5.8.0/bin/node" "/usr/local/bin/npm" "--registry=https://registry.npm.taobao.org" "--cache=/Users/Breezewish/.npm/.cache/cnpm" "--disturl=https://npm.taobao.org/dist" "--userconfig=/Users/Breezewish/.cnpmrc" "install" "optimist" "@my-company-name/example_private_module"
- npm ERR! node v5.8.0
- npm ERR! npm v3.7.3
- npm ERR! code E404
- npm ERR! 404 Not Found: @my-company-name/example_private_module
- npm ERR! 404
- npm ERR! 404 '@my-company-name/example_private_module' is not in the npm registry.
- npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
- npm ERR! 404
- npm ERR! 404 Note that you can also install from a
- npm ERR! 404 tarball, folder, http url, or git url.
- npm ERR! Please include the following file with any support request:
- npm ERR! /Users/Breezewish/Desktop/cnpm/example_project/npm-debug.log
- # ================================
- # Let's make cnpm working!
- $ npm login --registry http://127.0.0.1:7001 --scope=@my-company-name --userconfig=$HOME/.cnpmrc
- Username: myname
- Password:
- Email: (this IS public) myname@example.com
- Logged in as myname to scope @my-company-name on http://127.0.0.1:7001/.
- # ================================
- # TADA! Everything works!
- $ cnpm install optimist @my-company-name/example_private_module
- /Users/Breezewish/Desktop/cnpm/example_project
- ├── @my-company-name/example_private_module@1.0.0
- └── optimist@0.6.1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement