Nodes have three types of modules: built-in modules (in the node documentation), third-party modules (written by the bosses themselves), custom modules (the way to become bosses);
1. How to create a custom module:
Create a new JS file, such as:
letObj = {name:'AAA'SayHello:function(a){
console.log (hello +this.name)}}// Throw the object
module.exports = obj
Copy the code
How to use custom modules:
Then in the JS file to call
// Create an object to receive the module object
const obj = require('./ module.js')// This is the path to start the js fileperformconsole.log (obj) obj. Sayhello ();Copy the code
2. Use built-in modules
Const obj = require (‘ module name ‘)
Call directly according to official documentation
3. Third-party modules
Use NPM or CNPM to download related modules
Const obj = require (‘ module name ‘);
Then use it according to third-party documentation