npm发布模块

npm 是 Node.js 默认的模块管理器,用来安装和管理 node 模块。

npm 不需要单独安装。在安装 node 的时候,会连带一起安装 npm 。

输入npm查看使用帮助

WeiHeLi:~ weiheli$ npm

Usage: npm 

where  is one of:
    access, add-user, adduser, apihelp, author, bin, bugs, c,
    cache, completion, config, ddp, dedupe, deprecate, dist-tag,
    dist-tags, docs, edit, explore, faq, find, find-dupes, get,
    help, help-search, home, i, info, init, install, issues, la,
    link, list, ll, ln, login, logout, ls, outdated, owner,
    pack, ping, prefix, prune, publish, r, rb, rebuild, remove,
    repo, restart, rm, root, run-script, s, se, search, set,
    show, shrinkwrap, star, stars, start, stop, t, tag, team,
    test, tst, un, uninstall, unlink, unpublish, unstar, up,
    update, upgrade, v, verison, version, view, whoami

npm  -h     quick help on 
npm -l           display full usage info
npm faq          commonly asked questions
npm help   search for help on 
npm help npm     involved overview

Specify configs in the ini-formatted file:
    /Users/weiheli/.npmrc
or on the command line via: npm  --key value
Config info can be viewed via: npm help config

[email protected] /usr/local/lib/node_modules/npm

发布一个模块

(1) 一个最简单的模块

写一个最简单的模块

npm init

一路回车,连git都不指定,生成package.json

(2) 切换回默认源

npm config set registry http://registry.npmjs.org 

(3) 注册账号

https://www.npmjs.com/注册一个账号

WeiHeLi:~ weiheli$ npm adduser
Username: weiheli
Password: 
Email: (this IS public) [email protected]

成功之后,npm 会把认证信息存储在~/.npmrc中。

(4) 发布

npm publish

成功之后,可以在https://www.npmjs.com/登录查看发布的模块。

然后,就可以用npm install安装了。

(6) 删除已发布的模块

npm unpublish 模块名 --force

你可能感兴趣的:(Node.js)