1. Global ObjectAll modules can be called 1) global: represents the global environment where the Node is located, 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 process. For example, if you directly enter node in DOS or terminal window, you will enter the NODE command line mode (REPL environment). To exit, enter process.exit(); 3) console: refers to the built-in console module of Node, which provides standard input and standard output functions in the command line environment. Usually write console.log(), no need to say more 2. Global functions 1) Timer functions: There are 4 timer functions: setTimeout(), clearTimeout(), setInterval(), clearInterval(). 3. Global variables1) _filename: points to the name of the script currently running. 2) _dirname: points to the directory where the currently running script is located. 4. Quasi-global variablesThe local variables inside the module point to different objects depending on the module, but they are applicable to all modules and can be regarded as pseudo-global variables, mainly module, module.exports, exports, etc. The module variable refers to the current module. The module.exports variable represents the interface exported by the current module. When other files load the module, they actually read the module.exports variable.
It is important to point out here that the exports variable is actually a link to the module.exports object, which is equivalent to having a line of commands like this in the header of each module.
The result is that when exporting a module interface, you can add methods to the exports object, but you cannot directly point the exports variable to a function:
The above is invalid because it severs the link between exports and module.exports. However, it is possible to write the following. Knowledge point expansion: There is a special object in JavaScript called the global object. In browser JS, this global object is usually the Window object In NodeJS, the name of this global object is global. In NodeJS, there are three ways to define global variables: 1> Variables defined at the outermost level. Generally speaking, user code is not at the outermost level. There is only one case where this is possible: in an interpreter shell environment. 2> Define the variable as a property of the global object var global.x; 3>All variables defined implicitly (undefined, directly assigned variables) This is why implicit definitions are not recommended. Such variables defined as global variables will pollute the environment. This is the end of this article about nodejs global variables and global objects knowledge points and detailed usage. For more related nodejs global variables and global objects content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Time zone issues with Django deployed in Docker container
>>: A brief discussion on order reconstruction: MySQL sharding
This article example shares the specific code of ...
Table of contents Introduction Architecture Advan...
As a front-end developer, I can’t avoid IE’s pitf...
MySQL error: Parameter index out of range (1 >...
1. v-on event monitoring To listen to DOM events,...
This article mainly introduces the sql serial num...
Table of contents 1. Introduction Second practice...
The origin of the problem The first time I paid a...
1 Introduction Kong is not a simple product. The ...
<br />This example mainly studies two parame...
Introduction In the previous article, we installe...
1. left(name,4) intercepts the 4 characters on th...
This article uses examples to illustrate the prin...
First look at the example code: #/bin/bash cal da...
This article shares the specific code for JavaScr...