exit event (Cluster)

Event: 'exit' worker <cluster.Worker> code <Number> the exit code, if it exited normally. signal <String> the name of the signal (eg. 'SIGHUP') that caused the process to be killed. When any of the workers die the cluster module will emit the 'exit' event. This can be used to restart the worker by calling .fork() again. cluster.on('exit', (worker, code, signal) => { console.log('worker %d died (%s). restarting...', worker.process.pid, signal || code); cluste

module.exports

module.exports <Object> The module.exports object is created by the Module system. Sometimes this is not acceptable; many want their module to be an instance of some class. To do this, assign the desired export object to module.exports. Note that assigning the desired object to exports will simply rebind the local exports variable, which is probably not what you want to do. For example suppose we were making a module called a.js const EventEmitter = require('events'); module.exports

message.url

message.url Only valid for request obtained from http.Server. Request URL string. This contains only the URL that is present in the actual HTTP request. If the request is: GET /status?name=ryan HTTP/1.1\r\n Accept: text/plain\r\n \r\n Then request.url will be: '/status?name=ryan' If you would like to parse the URL into its parts, you can use require('url').parse(request.url). Example: $ node > require('url').parse('/status?name=ryan') { href: '/status?name=ryan', search: '?name=ryan'

util.debug()

util.debug(string) Stability: 0 - Deprecated: Use console.error() instead. Deprecated predecessor of console.error.

setFlagsFromString()

setFlagsFromString(string) Set additional V8 command line flags. Use with care; changing settings after the VM has started may result in unpredictable behavior, including crashes and data loss. Or it may simply do nothing. The V8 options available for a version of Node.js may be determined by running node --v8-options. An unofficial, community-maintained list of options and their effects is available here. Usage: // Print GC events to stdout for one minute. const v8 = require('v8'); v8.setFl

module.require()

module.require(id) id <String> Return: <Object> module.exports from the resolved module The module.require method provides a way to load a module as if require() was called from the original module. Note that in order to do this, you must get a reference to the module object. Since require() returns the module.exports, and the module is typically only available within a specific module's code, it must be explicitly exported in order to be used.

newListener event (EventEmitter)

Event: 'newListener' eventName <String> | <Symbol> The name of the event being listened for listener <Function> The event handler function The EventEmitter instance will emit it's own 'newListener' event before a listener is added to it's internal array of listeners. Listeners registered for the 'newListener' event will be passed the event name and a reference to the listener being added. The fact that the event is triggered before adding the listener has a subtle but im

process.setgid()

process.setgid(id) Note: this function is only available on POSIX platforms (i.e. not Windows, Android) Sets the group identity of the process. (See setgid(2).) This accepts either a numerical ID or a groupname string. If a groupname is specified, this method blocks while resolving it to a numerical ID. if (process.getgid && process.setgid) { console.log(`Current gid: ${process.getgid()}`); try { process.setgid(501); console.log(`New gid: ${process.getgid()}`); } catch

TypeError

Class: TypeError A subclass of Error that indicates that a provided argument is not an allowable type. For example, passing a function to a parameter which expects a string would be considered a TypeError. require('url').parse(function() { }); // throws TypeError, since it expected a string Node.js will generate and throw TypeError instances immediately as a form of argument validation.

stream.Writable

Class: stream.Writable stream.Writable is an abstract class designed to be extended with an underlying implementation of the stream._write(chunk, encoding, callback) method. Please see API for Stream Consumers for how to consume writable streams in your programs. What follows is an explanation of how to implement Writable streams in your programs. new stream.Writable([options]) options <Object> highWaterMark <Number> Buffer level when stream.write() starts returning false. Defau