exit event (Worker)

Event: 'exit' 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. Similar to the cluster.on('exit') event, but specific to this worker. const worker = cluster.fork(); worker.on('exit', (code, signal) => { if( signal ) { console.log(`worker was killed by signal: ${signal}`); } else if( code !== 0 ) { console.log(`worker exited with error code: ${code}`); } else { cons

vm.runInContext()

vm.runInContext(code, contextifiedSandbox[, options]) vm.runInContext() compiles code, then runs it in contextifiedSandbox and returns the result. Running code does not have access to local scope. The contextifiedSandbox object must have been previously contextified via vm.createContext(); it will be used as the global object for code. vm.runInContext() takes the same options as vm.runInThisContext(). Example: compile and execute different scripts in a single existing context. const util = r

connect event (http.ClientRequest)

Event: 'connect' function (response, socket, head) { } Emitted each time a server responds to a request with a CONNECT method. If this event isn't being listened for, clients receiving a CONNECT method will have their connections closed. A client server pair that show you how to listen for the 'connect' event. const http = require('http'); const net = require('net'); const url = require('url'); // Create an HTTP tunneling proxy var proxy = http.createServer( (req, res) => { res.writeHe

crypto.createHash()

crypto.createHash(algorithm) Creates and returns a Hash object that can be used to generate hash digests using the given algorithm. The algorithm is dependent on the available algorithms supported by the version of OpenSSL on the platform. Examples are 'sha256', 'sha512', etc. On recent releases of OpenSSL, openssl list-message-digest-algorithms will display the available digest algorithms. Example: generating the sha256 sum of a file const filename = process.argv[2]; const crypto = require(

fs.open()

fs.open(path, flags[, mode], callback) Asynchronous file open. See open(2). flags can be: 'r' - Open file for reading. An exception occurs if the file does not exist. 'r+' - Open file for reading and writing. An exception occurs if the file does not exist. 'rs' - Open file for reading in synchronous mode. Instructs the operating system to bypass the local file system cache. This is primarily useful for opening files on NFS mounts as it allows you to skip the potentially stale local cache.

buffer.equals()

buf.equals(otherBuffer) otherBuffer <Buffer> Return: <Boolean> Returns a boolean indicating whether this and otherBuffer have exactly the same bytes. const buf1 = Buffer.from('ABC'); const buf2 = Buffer.from('414243', 'hex'); const buf3 = Buffer.from('ABCD'); console.log(buf1.equals(buf2)); // Prints: true console.log(buf1.equals(buf3)); // Prints: false

buffer.write()

buf.write(string[, offset[, length]][, encoding]) string <String> Bytes to be written to buffer offset <Number> Default: 0 length <Number> Default: buffer.length - offset encoding <String> Default: 'utf8' Return: <Number> Numbers of bytes written Writes string to the Buffer at offset using the given encoding. The length parameter is the number of bytes to write. If the Buffer did not contain enough space to fit the entire string, only a partial amount of th

path.relative()

path.relative(from, to) Solve the relative path from from to to. At times we have two absolute paths, and we need to derive the relative path from one to the other. This is actually the reverse transform of path.resolve, which means we see that: path.resolve(from, path.relative(from, to)) == path.resolve(to) Examples: path.relative('C:\\orandea\\test\\aaa', 'C:\\orandea\\impl\\bbb') // returns '..\\..\\impl\\bbb' path.relative('/data/orandea/test/aaa', '/data/orandea/impl/bbb') // returns '

punycode.ucs2.encode()

punycode.ucs2.encode(codePoints) Creates a string based on an array of numeric code point values. punycode.ucs2.encode([0x61, 0x62, 0x63]); // 'abc' punycode.ucs2.encode([0x1D306]); // '\uD834\uDF06'

tlsSocket.localPort

tlsSocket.localPort The numeric representation of the local port.