Skip to content

Instantly share code, notes, and snippets.

@acidtone
Last active October 26, 2021 12:47
Show Gist options
  • Save acidtone/873e18b256e3feca52d36ead8b1d5318 to your computer and use it in GitHub Desktop.
Save acidtone/873e18b256e3feca52d36ead8b1d5318 to your computer and use it in GitHub Desktop.
Node: Default objects and properties

Node: Default objects and properties

A number of default objects and properties come with the Node environment.

Terminology

__filename : The absolute file name of the current module.

__dirname : The directory of the current module.

process Global Object : A global object provides various information sets about the runtime of a program.

process.argv : An array containing the command-line arguments passed when the Node.js process was launched.

this : The infamous this keyword returns an empty object by default.

global : The Node global object replaces the window object in browsers.

// The file name of the current module
console.log(__filename);
// The directory of the current module
console.log(__dirname);
// An array containing the command-line arguments passed when the Node.js process was launched
console.log(process.argv);
// The infamous `this` keyword
console.log(this);
// The Node global object
console.log(global);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment