Nodejs global variables and nodejs global variables
1. global
Similar to the window in the client javascript Runtime Environment
Module1.js:
Module. exports = {}; // The global variable global. varA = "abc ";
The global object can be omitted in actual use. It is the default root scope, which is equivalent to the window object in the web environment.
The global object has several useful attributes:
Console. log (_ dirname); // The current path console. log (_ filename); // path of the currently executed js file // global. process gets the current Process instance
2. process
Obtains information about the current Node process. It is generally used to obtain information such as environment variables.
Process. on ('exit ', function (code) {// the following code will never execute setTimeout (function () {console. log ("this code will not be executed") ;}, 0); console. log ('exit code: ', code) ;}); console. log ("program execution ended ");
3. console
Input and Output
Main. js:
Var c = require ("./calculator"); console. log (global. varA); // use the global object to access the "global" variable