node.js of CommonJS

 1、

(
  function(exports, require, module, __filename, __dirname) {
      console.log('This is a test.');  
  }  
);

  - Each file is a module, has its own scope

  - represents the module itself is in the internal module variables

  - module.exports property on behalf of external interface module

 

2, require properties

  - module is executed when the load after load the cache

  - Once a module is loaded cycle, it will only output section has been executed, execution is not yet part of the output. To avoid the development of two modules loaded each other.

 

3, node.js the global attributes and methods linked to the global

  - CommonJs

  - Buffer、process、console

  - timer

 

4, process process

  - node start the relevant parameters: argv, argv0, execArgv, execPath

const { argv, argv0, execArgv, execPath } = process;

argv.forEach(item => {
    console.log(item);
});

 

Guess you like

Origin www.cnblogs.com/xy-ouyang/p/11614098.html