您的位置:首页 > 产品设计 > 产品经理

npm小结

2016-03-17 20:57 429 查看
上一篇文章简单的介绍了module,exports,require的使用,也知道node有个核心模块,核心模块几乎提供了所有底层的操作,但是这远远不够开发者使用的,比如读写mysql,总不能每个人都去自己开发一套读写mysql的操作吧,那么有没有什么办法引入三方的模块,也就是大牛们开发的很好用的库呢,有,那就是npm。

这里就对npm做个简单的介绍吧。

npm是nodejs的最常用的包管理器,官网地址是:https://www.npmjs.com/,在这里你可以搜到大牛们贡献出来的常用的三方库。

npm安装:

curl -L https://www.npmjs.com/install.sh | sh


查看npm的版本:

npm -v
2.14.12


npm安装包:

npm install XXXX


npm安装全局包:

npm install XXXX -g


不过有时候要加上sudo,使用root权限安装。

还有很多命令,执行npm就可以看得到:

npm

Usage: npm <command>

where <command> 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 <cmd> -h     quick help on <cmd>
npm -l           display full usage info
npm faq          commonly asked questions
npm help <term>  search for help on <term>
npm help npm     involved overview

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

npm@2.14.12 /usr/local/lib/node_modules/npm


通过上面的命令的输出结果一行:

Specify configs in the ini-formatted file:
/home/user_name/.npmrc


我们打开这个文件:

registry=http://npm.myregistry-inc.com/

这里面存的是npm的一些配置,上面的配置代码包源。

修改这个文件换成其他的包源或者加上下面的参数:

npm install xxx --registry=https://registry.npm.taobao.org

至于我们自己怎么打包,怎么发包,后面再介绍吧。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: