Skip to content

Instantly share code, notes, and snippets.

@rich-97
Created March 5, 2017 23:08
Show Gist options
  • Save rich-97/4b82901e108dc4f3295e68d15ede14b0 to your computer and use it in GitHub Desktop.
Save rich-97/4b82901e108dc4f3295e68d15ede14b0 to your computer and use it in GitHub Desktop.
A cheatsheet for modules of NodeJS.

process

/* Events */

process.on('exit', function(code) {})             // Emitted when the process is about to exit
process.on('uncaughtException', function(err) {}) // Emitted when an exception bubbles all the way back to the event loop. (should not be used)

/* Properties */

process.stdout       // A writable stream to stdout.
process.stderr       // A writable stream to stderr.
process.stdin        // A readable stream for stdin.
process.argv         // An array containing the command line arguments.
process.env          // An object containing the user environment.
process.execPath     // This is the absolute pathname of the executable that started the process.
process.execArgv     // This is the set of node-specific command line options from the executable that started the process.
process.arch         // What processor architecture you're running on: 'arm', 'ia32', or 'x64'.
process.config       // An Object containing the JavaScript representation of the configure options that were used to compile the current node executable.
process.pid          // The PID of the process.
process.platform     // What platform you're running on: 'darwin', 'freebsd', 'linux', 'sunos' or 'win32'.
process.title        // Getter/setter to set what is displayed in 'ps'.
process.version      // A compiled-in property that exposes NODE_VERSION.
process.versions     // A property exposing version strings of node and its dependencies.
process.maxTickDepth // Callbacks passed to process.nextTick will usually be called at the end of the current flow of execution, and are thus approximately as fast as calling a function synchronously.

/* Methods */

process.abort()                     // This causes node to emit an abort. This will cause node to exit and generate a core file.
process.chdir(dir)                  // Changes the current working directory of the process or throws an exception if that fails.
process.cwd()                       // Returns the current working directory of the process.
process.exit([code])                // Ends the process with the specified code. If omitted, exit uses the 'success' code 0.
process.getgid()                    // Gets the group identity of the process.
process.setgid(id)                  // Sets the group identity of the process.
process.getuid()                    // Gets the user identity of the process.
process.setuid(id)                  // Sets the user identity of the process.
process.getgroups()                 // Returns an array with the supplementary group IDs.
process.setgroups(grps)             // Sets the supplementary group IDs.
process.initgroups(user, extra_grp) // Reads /etc/group and initializes the group access list, using all groups of which the user is a member.
process.kill(pid, [signal])         // Send a signal to a process. pid is the process id and signal is the string describing the signal to send.
process.memoryUsage()               // Returns an object describing the memory usage of the Node process measured in bytes.
process.nextTick(callback)          // On the next loop around the event loop call this callback.
process.umask([mask])               // Sets or reads the process's file mode creation mask.
process.uptime()                    // Number of seconds Node has been running.
process.hrtime()                    // Returns the current high-resolution real time in a [seconds, nanoseconds] tuple Array.

path

/* Properties */

path.sep        // The platform-specific file separator. '\\' or '/'.
path.delimiter  // The platform-specific path delimiter, '' or ':'.

/* Methods */

path.normalize(p)                  // Normalize a string path, taking care of '..' and '.' parts.
path.join([path1], [path2], [...]) // Join all arguments together and normalize the resulting path.
path.resolve([from ...], to)       // Resolves 'to' to an absolute path.
path.relative(from, to)            // Solve the relative path from 'from' to 'to'.
path.dirname(p)                    // Return the directory name of a path. Similar to the Unix dirname command.
path.basename(p, [ext])            // Return the last portion of a path. Similar to the Unix basename command.
path.extname(p)                    // Return the extension of the path, from the last '.' to end of string in the last portion of the path.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment