Difference between revisions of "Node.js (简体中文)"
m |
|||
Line 3: | Line 3: | ||
{{TranslationStatus (简体中文)|Node.js|2014-08-11|329745}} | {{TranslationStatus (简体中文)|Node.js|2014-08-11|329745}} | ||
{{Translateme (简体中文)}} | {{Translateme (简体中文)}} | ||
− | [http://nodejs.org/ Node.js] | + | [http://nodejs.org/ Node.js] 是一个 javascript 运行环境,并附带有常用的库. |
它使用了 [https://code.google.com/p/v8/ Google's V8 引擎] 在浏览器外执行代码. | 它使用了 [https://code.google.com/p/v8/ Google's V8 引擎] 在浏览器外执行代码. | ||
由于其是事件驱动、非阻塞 I/O 模型,它适合于实时 web 应用. | 由于其是事件驱动、非阻塞 I/O 模型,它适合于实时 web 应用. |
Revision as of 12:45, 16 August 2014
Node.js 是一个 javascript 运行环境,并附带有常用的库. 它使用了 Google's V8 引擎 在浏览器外执行代码. 由于其是事件驱动、非阻塞 I/O 模型,它适合于实时 web 应用.
Contents
安装
Node Packaged Modules
npm 是官方的node.js包管理器,已包含在 nodejs 中.
使用npm管理包
安装软件包
任何包可以用以下命令安装:
$ npm install packageName
这个命令会将包安装在当前目录下 node_modules
目录内,可执行命令(如果有)安装在 node_modules/.bin
目录下.
作为系统级的全局安装使用 -g
选项:
# npm -g install packageName
默认情形下这个命令会将包安装至 /usr/lib/node_modules/npm
,需要管理员权限.
For a user-wide installation you can configure npm
to use a local folder instead.
This can be done in various ways:
- Manually with the
--prefix
command line flag (e.g.npm -g install packageName --prefix ~/.node_modules
). - Using the
npm_config_prefix
environment variable. - Using a user config file
~/.npmrc
.
First method is not recommended since you need to remember the location and give it as the parameter each time you do an operation.
For the second method simply add the following lines to your shell configuration file (e.g. .bash_profile
).
PATH=$PATH:~/.node_modules/bin export npm_config_prefix=~/.node_modules
Do not forget to log out and log back in or restart your shell accordingly.
For the third method you can use the command:
$ npm config edit
You can then find the prefix
option and set a desired location:
prefix=~/.node_modules
Do not forget to delete the preceding ;
on the line or it will be read as a comment.
You can now add the location of your executables to your shell configuration file (e.g. .bash_profile
).
PATH=$PATH:~/.node_modules/bin
Again do not forget to log out and log back in or restart your shell accordingly.
Updating packages
Updating packages is as simple as
$ npm update packageName
For the case of globally installed packages ( -g
)
# npm update -g packageName
Updating All Packages
However, sometimes you may just wish to update all packages. Be it locally or globally. Leaving off the packageName npm
will attempt to update all the packages
$ npm update
or add the -g
flag to update globally installed packages
# npm update -g
Removing packages
To remove a package installed with the -g
switch simply use:
# npm -g uninstall packageName
to remove a local package drop the switch and run:
$ npm uninstall packageName
Listing packages
To show a tree view of the installed packages use:
# npm -g list
Managing packages with pacman
Some node.js packages can be found in Arch User Repository with the name nodejs-packageName
.
Additional Resources
For further information on nodejs and use of its official package manager npm you may wish to consult the following external resources
- NodeJs Documentation Documentation and Tutorials for Node
- NodeJS Community Webpage
- API Documentation Official
npm
API documentation - IRC channel #node.js on irc.freenode.net