SIGINT event (Readline)

Event: 'SIGINT' function () {} Emitted whenever the input stream receives a ^C, respectively known as SIGINT. If there is no SIGINT event listener present when the input stream receives a SIGINT, pause will be triggered. Example of listening for SIGINT: rl.on('SIGINT', () => { rl.question('Are you sure you want to exit?', (answer) => { if (answer.match(/^y(es)?$/i)) rl.pause(); }); });

script.runInThisContext()

script.runInThisContext([options]) Similar to vm.runInThisContext() but a method of a precompiled Script object. script.runInThisContext() runs script's compiled code and returns the result. Running code does not have access to local scope, but does have access to the current global object. Example of using script.runInThisContext() to compile code once and run it multiple times: const vm = require('vm'); global.globalVar = 0; const script = new vm.Script('globalVar += 1', { filename: 'myfi

assert.ok()

assert.ok(value[, message]) Tests if value is truthy. It is equivalent to assert.equal(!!value, true, message). If value is not truthy, an AssertionError is thrown with a message property set equal to the value of the message parameter. If the message parameter is undefined, a default error message is assigned. const assert = require('assert'); assert.ok(true); // OK assert.ok(1); // OK assert.ok(false); // throws "AssertionError: false == true" assert.ok(0); // throws "AssertionErr

process.execPath

process.execPath This is the absolute pathname of the executable that started the process. Example: /usr/local/bin/node

exit event (Process)

Event: 'exit' Emitted when the process is about to exit. There is no way to prevent the exiting of the event loop at this point, and once all 'exit' listeners have finished running the process will exit. Therefore you must only perform synchronous operations in this handler. This is a good hook to perform checks on the module's state (like for unit tests). The callback takes one argument, the code the process is exiting with. This event is only emitted when Node.js exits explicitly by process.

path.resolve()

path.resolve([from ...], to) Resolves to to an absolute path. If to isn't already absolute from arguments are prepended in right to left order, until an absolute path is found. If after using all from paths still no absolute path is found, the current working directory is used as well. The resulting path is normalized, and trailing slashes are removed unless the path gets resolved to the root directory. Non-string from arguments are ignored. Another way to think of it is as a sequence of cd c

System Error

Class: System Error error.code error.errno Returns a string representing the error code, which is always E followed by a sequence of capital letters, and may be referenced in man 2 intro. The properties error.code and error.errno are aliases of one another and return the same value. error.syscall Returns a string describing the syscall that failed.

dns.resolveSoa()

dns.resolveSoa(hostname, callback) Uses the DNS protocol to resolve a start of authority record (SOA record) for the hostname. The addresses argument passed to the callback function will be an object with the following properties: nsname hostmaster serial refresh retry expire minttl { nsname: 'ns.example.com', hostmaster: 'root.example.com', serial: 2013101809, refresh: 10000, retry: 2400, expire: 604800, minttl: 3600 }

process.send()

process.send(message[, sendHandle[, options]][, callback]) message <Object> sendHandle <Handle object> options <Object> callback <Function> Return: <Boolean> When Node.js is spawned with an IPC channel attached, it can send messages to its parent process using process.send(). Each will be received as a 'message' event on the parent's ChildProcess object. Note: this function uses JSON.stringify() internally to serialize the message. If Node.js was not s

interface.setPrompt()

rl.setPrompt(prompt) Sets the prompt, for example when you run node on the command line, you see > , which is Node.js's prompt.