The following global variables exist in Node.js: Global object: global Core module: process, console, require Runtime environment variables: __dirname, __filename, __line, __column Constants: undefined, null, NaN, Infinity, - Infinity
Global variables in Node.js
There are several built-in global variables in Node.js:
1. Global object
global
: Represents the global object of the currently executing script. All other global variables are properties of this object. 2. Core module
#process
: Provides detailed information and control of the Node.js process. console
: Provides console output and debugging functions. require
: used to load and access other modules. 3. Runtime environment variable
#__dirname
: Contains the absolute path to the directory where the current module is located. __filename
: Contains the absolute path of the current module file. __line
: The line number of the line of code currently being executed. __column
: The column number of the line of code currently being executed. 4. Constant
undefined
: Undefined value. null
: Indicates a null value. NaN
: non-numeric value. Infinity
: Positive infinity. -Infinity
: Negative infinity. Using global variables
Global variables can be accessed directly from any Node.js script. For example:
<code class="javascript">console.log(global); console.log(process.pid); console.log(__dirname);</code>
Note:
The above is the detailed content of What are the global variables in nodejs. For more information, please follow other related articles on the PHP Chinese website!