One
concept
Nodejs in addition to its core module provides external module may also use custom third-party modules
Nodejs by a third-party modules package composition can be carried out on a set of modules by coating with interdependence unified management
You can https://www.npmjs.com
find packages
in modules similar to Python
Simple to use
Download package:
npm i 包名
(Or npm install 包名
)
Can be used directly by require ()
var http=require("http");
var sd = require('silly-datetime');
var app=http.createServer(function(req,resp){
resp.writeHead(200,{"Content-Type":"text/html;charset=utf-8"});
var d=sd.format(new Date(), 'YYYY-MM-DD HH:mm');
resp.write(d);
resp.end();
});
app.listen(8001,"127.0.0.1");
success:
Second, npm
concept
npm is the world's largest open source ecosystem through a wide variety of package npm download
the source code (package) can https://www.npmjs.com
find
npm is a package management tool installed with NodeJS and can solve many problems in NodeJS code deployment
Common usage scenarios:
- Allow users to download third-party packages written by others from the NPM server for local use
- Allow users to download and install command-line programs (tools) written by others from the NPM server for local use (such as supervisor)
- Allow users to upload their own packages or command line programs to the NPM server for others to use
Common commands
Check the npm version:
npm -v
Install the module:
npm install 模块名
Example:npm install jquery
Uninstall the module:
npm uninstall 模块名
Example:npm uninstall jquery
Of course, you can also delete the folder directly
View all packages installed in the current directory:
npm list
Check the version of a package:
npm info 模块名
Install the specified version of the package:
npm install 模块名@版本