Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js
  • 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.
          
    • 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.
    • stdin - NOTE: RESEARCH
    • stdout - NOTE: RESEARCH
  • 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');
  • global - just window object in a browser, can be accessed from anywhere in the application.

 

  • path
    • path.normalize
    • path.join
    • path.dirname, path. basename, path.extname
  • fs (file-system)
  • os (operating-system)
  • util (general utilities)
    • util.inherits
    • util.log
    • util.isArray
    • util.isDate
    • util.isError
  • require (function)
  • events
  • stream
    • stream.Readable
    • stream.Writebale
    • stream.Duplex
    • stream.Transform
    • NOTE! all the above inherit from Stream which you should not use directly.
    • NOTE! Stream inherits from EventEmitter

 

 

Requiring a module steps made by node

Then the follow is the logic followed by Node.js for a require('something') statement:

• If something is a core module, return it.
• If something is a relative path (starts with ‘./’ , ‘../’) return that file OR folder.
• If not, look for node_modules/filename or node_modules/foldername each level up until you
find a file OR folder that matches something.


When matching a file OR folder:, follow these steps:
• If it matched a file name, return it.
• If it matched a folder name and it has package.json with main, return that file.
• If it matched a folder name and it has an index file, return it.
 

Important Globals

Tomas Katz
Module by Tomas Katz, updated more than 1 year ago

Description

Important Globals
No tags specified