Node.js Global Objects

Node.js worldwide items are worldwide in nature and accessible in all modules. You don't have to incorporate these items in your application; rather they can be utilized straightforwardly. These items are modules, capacities, strings and article and so on. A portion of these articles aren't very the worldwide extension yet in the module scope.
  • __dirname
  • __filename
  • Console
  • Process
  • Buffer
  • setImmediate(callback[, arg][, ...])
  • setInterval(callback, delay[, arg][, ...])
  • setTimeout(callback, delay[, arg][, ...])
  • clearImmediate(immediateObject)
  • clearInterval(intervalObject)
  • clearTimeout(timeoutObject)

Node.js __dirname

It is a string. It specifies the name of the directory that currently contains the code.

File: global-example1.js

  1. console.log(__dirname);   

Open Node.js command prompt and run the following code:

  1. node global-example1.js   

Node.js __filename

It specifies the filename of the code being executed. This is the resolved absolute path of this code file. The value inside a module is the path to that module file.

File: global-example2.js

  1. console.log(__filename);   

Open Node.js command prompt and run the following code:

  1. node global-example2.js   

welookups is optimized for learning.© welookups. 2018 - 2020 All Right Reserved and you agree to have read and accepted our term and condition.