- npm 是什么?
- 如何安装 npm 并管理 npm 版本
- How to Prevent Permissions Errors
- 如何安装本地包
- Working with package.json
- 如何更新本地安装的包
- 如何卸载本地安装的包
- 如何安装全局包
- 如何更新全局安装的包
- 如何卸载全局安装的包
- 如何创建 Node.js 模块
- How to Publish & Update a Package
- 如何使用语义化版本
- How to Work with Scoped Packages
- How to Label Packages with Dist-tags
- How to Use Two-Factor Authentication
- How to Work with Security Tokens
- How to Change Profile Settings from the CLI
- Understanding Packages and Modules
- npm-access
- npm-adduser
- npm-audit
- npm-bin
- npm-bugs
- npm-build
- npm-bundle
- npm-cache
- npm-ci
- npm-completion
- npm-config
- npm-dedupe
- npm-deprecate
- npm-dist-tag
- npm-docs
- npm-doctor
- npm-edit
- npm-explore
- npm-help
- npm-help-search
- npm-hook
- npm-init
- npm-install
- npm install-ci-test -- Install a project with a clean slate and run tests
- npm install-test -- 安装依赖包并运行测试
- npm-link
- npm-logout
- npm-ls
- npm
- npm-org
- npm-outdated
- npm-owner
- npm-pack
- npm-ping
- npm-prefix
- npm-profile
- npm-prune
- npm-publish
- npm-rebuild
- npm-repo
- npm-restart
- npm-root
- npm-run-script
- npm-search
- npm-shrinkwrap
- npm-star
- npm-stars
- npm-start
- npm-stop
- npm-team
- npm-test
- npm-token
- npm-uninstall
- npm-unpublish
- npm-update
- npm-version
- npm-view
- npm-whoami
- npm-coding-style
- npm-config
- npm-developers
- npm-disputes
- npm-orgs
- npm-registry
- npm-removal
- npm-scope
- npm-scripts
- semver
- npm-folders
- npmrc
- package-lock.json
- npm-package-locks
- package.json
- npm-shrinkwrap.json
- 尝试 node 的最新稳定版本
- Try the latest stable version of npm
- 如果 npm 损坏了
- Try clearing the npm cache
- Common Errors
npm-developers
Developer Guide
Description
So, you've decided to use npm to develop (and maybe publish/deploy) your project.
Fantastic!
There are a few things that you need to do above the simple steps that your users will do to install your program.
About These Documents
These are man pages. If you install npm, you should be able to then do man npm-thing
to get the documentation on a particular topic, or npm help thing
to see the same information.
What is a package
A package is:
- a) a folder containing a program described by a package.json file
- b) a gzipped tarball containing (a)
- c) a url that resolves to (b)
- d) a
<name>@<version>
that is published on the registry with (c) - e) a
<name>@<tag>
that points to (d) - f) a
<name>
that has a "latest" tag satisfying (e) - g) a
git
url that, when cloned, results in (a).
Even if you never publish your package, you can still get a lot of benefits of using npm if you just want to write a node program (a), and perhaps if you also want to be able to easily install it elsewhere after packing it up into a tarball (b).
Git urls can be of the form:
git://github.com/user/project.git#commit-ish
git+ssh://user@hostname:project.git#commit-ish
git+http://user@hostname/project/blah.git#commit-ish
git+https://user@hostname/project/blah.git#commit-ish
The commit-ish
can be any tag, sha, or branch which can be supplied as an argument to git checkout
. The default is master
.
The package.json File
You need to have a package.json
file in the root of your project to do much of anything with npm. That is basically the whole interface.
See Use a If you want to double check that your package will include only the files you intend it to when published, you can run the More info at This is important. If you can not install it locally, you'll have problems trying to publish it. Or, worse yet, you'll be able to publish it, but you'll be publishing a broken or pointless package. So don't do that. In the root of your package, do this: That'll show you that it's working. If you'd rather just create a symlink package that points to your working directory, then do this: Use To test a local install, go into some other folder, and then do: to install it locally into the node_modules folder in that other place. Then go into the node-repl, and try using require("my-thing") to bring in your module's main module. Create a user with the adduser command. It works like this: and then follow the prompts. This is documented better in Publish your package This part's easy. In the root of your folder, do this: You can give publish a url to a tarball, or a filename of a tarball, or a path to a folder. Note that pretty much everything in that folder will be exposed by default. So, if you have secret stuff in there, use a Send emails, write blogs, blab in IRC. Tell the world how easy it is to install your program!Keeping files out of your package
.npmignore
file to keep stuff out of your package. If there's no .npmignore
file, but there is a .gitignore
file, then npm will ignore the stuff matched by the .gitignore
file. If you want to include something that is excluded by your .gitignore
file, you can create an empty .npmignore
file to override it. Like git
, npm
looks for .npmignore
and .gitignore
files in all subdirectories of your package, not only the root directory..npmignore
files follow the Testing whether your .npmignore
or files
config worksnpm pack
command locally which will generate a tarball in the working directory, the same way it does for publishing.Link Packages
npm link
is designed to install a development package and see the changes in real time without having to keep re-installing it. (You do need to either re-link or npm rebuild -g
to update compiled packages, of course.)Before Publishing: Make Sure Your Package Installs and Works
npm install . -g
npm link
npm ls -g
to see if it's there.cd ../some-other-folder
npm install ../my-package
Create a User Account
npm adduser
npm publish
.npmignore
file to list out the globs to ignore, or publish from a fresh checkout.Brag about it
See Also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论