1. Module concept
Native module: The native module provided by the node. JS API, the native module is loaded at startup.
File module: Dynamic loading module, which is implemented and completed by the native modules module.
The file module needs to be loaded by calling the Require method.
node. JS has a cache of both modules and does not repeat the overhead to load the module, reading only the corresponding data.
Invocation of native modules
The node. js API require loads the appropriate node. JS module and returns a node. JS Module object after the load succeeds.
The object owns all the methods and properties of the module.
var HttpModule = require ("http");
Httpmodule.createserver (function (res,req)). Listen ();
The invocation of the file module
The path must be specified when loading
absolute path:var test = require ('/path/.../test.js ');
relative path:var test = require ('./test.js ');
In a file module, only exports and Module.exports objects are exposed to external properties and methods to be invoked by returning require objects
NPM Package Manager (need to maintain network)
To download the required modules via NPM, thenpm Install command will be added in this directory Node_ Modules folder to store downloaded modules
Download NPM Install module
Uninstalling NPM Uninstall model
NPM Install-g Express
strong> strong> npm install Express
Express App
Node App.js
strong> strong> npm install Socket.io
strong> strong> NPM install MySQL
Node. js module and NPM