May 10, 2021 Node.js
In the Node .js we can access the global object directly.
These objects are available in all modules, some not in the global scope but in the module scope, as described in this article.
In a browser, the global scope is the top-level domain. I
f you define the variable var something within
var something
it will be the global variable.
In Node, the top-level domain is not
var something
a global domain;
The process object. See the process object section.
Used to print stdout and stderr. See console chapter.
Used to process binary data. See the buffer section.
Introduce modules. S
ee
modules
section.
require
not actually global, but is valid for each local module.
Use the
require()
mechanism to find the mode location, but do not load the module, only return the resolved file name.
This object is cached when the module is introduced.
By removing the object key value, the next call
require
overloads the module.
稳定性: 0 - 抛弃
Instructs
require
on how to handle specific file extensions.
Treat
.sjs
file
.js
file:
require.extensions['.sjs'] = require.extensions['.js'];
Discard the previous list used to load on-demand non-JavaScript modules to node. In fact, there are better ways to solve this problem, such as loading modules with other node programs or compiling JavaScript in advance.
This function may never be removed because the module system is locked. Changing it can create a bug, so it's best not to move it.
The file name of the code being executed is the relative path. F or the main program, this does not necessarily use the same file name as on the command line. The value in the module is the path to the module file.
Columns such as the
/Users/mjr
node example.js
console.log(__filename);
// /Users/mjr/example.js
__filename
not global, but module-local.
The name of the folder in which the script code is executed.
Columns such as the
/Users/mjr
node example.js
console.log(__dirname);
// /Users/mjr
__dirname
not global, but module-local.
The reference to the current module.
With
require()
module.exports
module output is available.
module
is not global, but the module is local.
For more information, see module system documentation.
module.exports
For information on when
exports
module.exports
you can refer
to the module system documentation.
module
is not global, but the module is local.
For more information, see module system documentation.
See module for more information.
The callback
ms
called back at least after ms milliseconds.
Actual latency depends on external factors, such as the granularity and load of the operating system.
The timeout values have a valid range of 1-2,147,483,647. I f the range is exceeded, it will change to 1 millisecond. In general, the timer should not exceed 24.8 days.
Returns a handle value that represents the timer.
Stop a timer that
setTimeout()
T
he callback will no longer be executed.
The
ms
function cb is called every ms
cb
T
he actual interval depends on external factors, such as the granularity of the operating system and the system load.
Usually greater
ms
The effective range of the interval values is 1-2,147,483,647. I f the range is exceeded, it will change to 1 millisecond. In general, the timer should not exceed 24.8 days.
Returns a handle value that represents the timer.
Stop a timer that
setInterval()
T
he callback will no longer be executed.
The timer function is a global variable. See the timers section.