Module 8 of 14 · Text
Important Globals
- console
- timers (setInterval, setTimeout, clearInterval, clearTimeout)
- _filename, _dirname (local global, specific to file scope)
- This variable exists in every files scope, and provide the full path to the file & directory.
- process
- process.argv (for command line arguments)
- When a file is executed using the command line ( for example an NPM start script that passes parameters to an installed package) and passed parameters, these parameters can be accessed inside the file using the process.argv which is an array of strings.
The first element of the array will be the name of the process running the script, mainly it will be "node".
The second element of the array will be the full file path to the script thats executing, for example '/path/to/file/on/your/filesystem/argv.js'.
The elements following will all be the different arguments passed into the execution command.
so an example for the returned array from process.argv will be something like: [ 'node', '/path/to/file/on/your/filesystem/argv.js', 'foo', 'bar', 'bas' ].
to get only the arguments you can splice the array from the 3rd element to the end of the array.
- When a file is executed using the command line ( for example an NPM start script that passes parameters to an installed package) and passed parameters, these parameters can be accessed inside the file using the process.argv which is an array of strings.
- process.nextTick (event loop callback)
- A highly efficient and simple function, that takes a callback function which is added to the start of every event loop Q execution.
This callback function will always be the first task in an event loop Q execution.
What important to notice about this function, is that its the first javascript function to execute in every event loop iteration, everything before it is C and everything after it is Javascrpit.
- A highly efficient and simple function, that takes a callback function which is added to the start of every event loop Q execution.
- stdin - NOTE: RESEARCH
- stdout - NOTE: RESEARCH
- process.argv (for command line arguments)
- Buffer (global class)
- A globally defined class used to convert data between different types of encoding, for example UTF to ASCII, or ASCII to binary.
example:
var buffer = new Buffer(str, 'utf-8');
var roundTrip = buffer.toString('utf-8');
- A globally defined class used to convert data between different types of encoding, for example UTF to ASCII, or ASCII to binary.
- global - just window object in a browser, can be accessed from anywhere in the application.