1. Global objects
All modules can be called
1) Global: Indicates that node is in an environment similar to the Window object in the browser.
2) Process: points to Node's built-in process module, allowing developers to interact with the current processes.
For example, if you enter node directly in a DOS or terminal window, you will enter node's command line (REPL environment). Exit to exit, you can enter Process.exit ();
3) Console: Point to Node's built-in console module, which provides standard input and standard output functions in the command line environment.
is usually written console.log (), needless to say
2. Global functions:
1) Timer function: A total of 4, respectively, is settimeout (), cleartimeout (), SetInterval (), Clearinterval ().
2) require: for loading modules. The King's house in the common See, Tri Yutong several times before the smell.
3. Global variables:
1) _filename: Point to the currently running script file name.
2) _dirname: Point to the directory where the currently running script resides.
4, quasi-global variables
Local variables within the module, pointing to different objects depending on the module, but all modules are applicable, can be regarded as pseudo-global variables, mainly module, module.exports, exports and so on.
The module variable refers to the current block. The module.exports variable represents the external output interface of the current module, and the other file loads the module, in effect reading the module.exports variable.
The identifier of the Module.id module, usually the file name of the module.
The file name of the Module.filename module.
Module.loaded returns a Boolean value that indicates whether the module has finished loading.
Module.parent returns the module that uses the module.
Module.children returns an array that represents the other modules to be used by the module.
It should be noted here that the exports variable is actually a link to the Module.exports object, which is equivalent to a command on each module's head and one row.
var exports = Module.exports;
As a result, you can add methods to the exports object when the external output module interfaces, but you cannot directly point the exports variable to a function:
Exports = function (x) {console.log (x);};
The above notation is invalid because it cuts off the link between exports and module.exports. However, it is possible to write the following.
[JavaScript]View Plaincopy
- Exports.area = function (r) {
- return Math.PI * R * r;
- };
- Exports.circumference = function (r) {
- return 2 * Math.PI * r;
- };
If you feel that the difference between exports and module.exports is difficult to distinguish, a simple way to do this is to abandon the use of exports, using only module.exports.
Reference article:
Http://javascript.ruanyifeng.com/nodejs/basic.html#toc5
Global objects and global variables for node. js