In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "how to use the npm command to install the Node.js module". In the daily operation, I believe many people have doubts about how to use the npm command to install the Node.js module. The editor consulted all kinds of materials and sorted out a simple and easy-to-use method of operation. I hope it will be helpful to answer the doubt of "how to use the npm command to install the Node.js module". Next, please follow the editor to study!
Use the npm command to install the module
The syntax format of the npm installation Node.js module is as follows:
$npm install
For the following example, we use the npm command to install the commonly used Node.js web framework module express:
$npm install express
After installation, the express package is placed in the node_modules directory under the project directory, so you only need to require ('express') in the code without specifying the third-party package path.
Var express = require ('express'); global installation versus local installation
The package installation of npm is divided into local installation (local) and global installation (global). From the point of view of the command line, the only difference is whether there is-g, such as
Npm install express # Local installation npm install express-g # Global installation
If the following error occurs:
Npm err! Error: connect ECONNREFUSED 127.0.0.1:8087
The solution is:
$npm config set proxy null local installation
1. Place the installation package under. / node_modules (the directory where the npm command was run), and if there is no node_modules directory, the node_modules directory will be generated in the directory where the npm command is currently executed.
two。 Locally installed packages can be introduced through require ().
Global installation
1. Put the installation package under / usr/local or your node installation directory.
two。 You can use it directly on the command line.
If you want to have both, you need to install it in two places or use npm link.
Next, we install express globally.
$npm install express-g
The installation process outputs the following, and the first line outputs the version number and installation location of the module.
Express@4.13.3 node_modules/express ├── escape-html@1.0.2 ├── range-parser@1.0.2 ├── merge-descriptors@1.0.0 ├── array-flatten@1.1.1 ├── cookie@0.1.3 ├── utils-merge@1.0.0 ├── parseurl@1.3.0 ├── cookie-signature@1.0.6 ├── methods@1.1.1 ├── fresh@0 .3.0 ├── vary@1.0.1 ├── path-to-regexp@0.1.7 ├── content-type@1.0.1 ├── etag@1.7.0 ├── serve-static@1.10.0 ├── content-disposition@0.5.0 ├── depd@1.0.1 ├── qs@4.0.0 ├── finalhandler@0.4.0 (unpipe@1.0.0) ├── on-finished@ 2.3.0 (ee-first@1.1.1) ├── proxy-addr@1.0.8 (forwarded@0.1.0 Ipaddr.js@1.0.1) ├── debug@2.2.0 (ms@0.7.1) ├── type-is@1.6.8 (media-typer@0.3.0, mime-types@2.1.6) ├── accepts@1.2.12 (negotiator@0.5.3, mime-types@2.1.6) └── send@0.13.0 (destroy@1.0.3, statuses@1.2.1, ms@0.7.1 Mime@1.3.4, http-errors@1.3.1) View installation information
You can view all globally installed modules using the following command:
$npm list-g ├─┬ cnpm@4.3.2 │ ├── auto-correct@1.0.0 │ ├── bagpipe@0.3.5 │ ├── colors@1.1.2 ├─┬ ├─┬ │ │ └── graceful-readlink@1.0.1 │ ├─┬ cross-spawn@0.2.9 │ │ └── lru-cache@2.7.3.
If you want to see the version number of a module, you can use the following command:
Npm list gruntprojectName@projectVersion / path/to/project/folder └── grunt@0.4.1 at this point, the study on "how to use the npm command to install the Node.js module" is over. I hope I can solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.