assert.fail(actual, expected, message, operator)
Throws an exception that displays the values for actual and expected separated by the provided operator.
assert(value, message), assert.ok(value, [message])
Tests if value is a true value, it is equivalent to assert.equal(true, value, message);
assert.equal(actual, expected, [message])
Tests shallow, coercive equality with the equal comparison operator ( == ).
assert.notEqual(actual, expected, [message])
Tests shallow, coercive non-equality with the not equal comparison operator ( != ).
assert.deepEqual(actual, expected, [message])
Tests for deep equality.
assert.notDeepEqual(actual, expected, [message])
Tests for any deep inequality.
assert.strictEqual(actual, expected, [message])
Tests strict equality, as determined by the strict equality operator ( === )
assert.notStrictEqual(actual, expected, [message])
Tests strict non-equality, as determined by the strict not equal operator ( !== )
assert.throws(block, [error], [message])
Expects block to throw an error. error can be constructor, regexp or validation function.
assert.doesNotThrow(block, [error], [message])
Expects block not to throw an error, see assert.throws for details.
assert.ifError(value)
Tests if value is not a false value, throws if it is a true value. Useful when testing the first argument, error in callbacks.
new Buffer(size)
Allocates a new buffer of size octets.
new Buffer(array)
Allocates a new buffer using an array of octets.
new Buffer(str, encoding='utf8')
Allocates a new buffer containing the given str.
buffer.write(string, offset=0, length=buffer.length-offset, encoding='utf8')
Writes string to the buffer at offset using the given encoding. length is the number of bytes to write. Returns number of octets written. If buffer did
not contain enough space to fit the entire string, it will write a partial
amount of the string. The method will not write partial characters.
buffer.toString(encoding, start=0, end=buffer.length)
Decodes and returns a string from buffer data encoded with encoding beginning at start and ending at end.
buffer[index]
Get and set the octet at index. The values refer to individual bytes, so the legal range is between 0x00 and 0xFF hex or 0 and 255.
Buffer.isBuffer(obj)
Tests if obj is a Buffer.
Buffer.byteLength(string, encoding='utf8')
Gives the actual byte length of a string. This is not the same as String.prototype.length since that returns the number of characters in a
string.
buffer.length
The size of the buffer in bytes. Note that this is not necessarily the size of the contents. length refers to the amount of memory allocated for the
buffer object. It does not change when the contents of the buffer are changed.
buffer.copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
Does copy between buffers. The source and target regions can be overlapped.
buffer.slice(start, end=buffer.length)
Returns a new buffer which references the same memory as the old, but offset and cropped by the start and end
indexes.
buffer.readUInt8(offset, noAssert=false)
Reads an unsigned 8 bit integer from the buffer at the specified offset.
buffer.readUInt16LE(offset, noAssert=false)
buffer.readUInt16BE(offset, noAssert=false)
buffer.readUInt16BE(offset, noAssert=false)
Reads an unsigned 16 bit integer from the buffer at the specified offset with specified endian format.
buffer.readUInt32LE(offset, noAssert=false)
buffer.readUInt32BE(offset, noAssert=false)
buffer.readUInt32BE(offset, noAssert=false)
Reads an unsigned 32 bit integer from the buffer at the specified offset with specified endian format.
buffer.readInt8(offset, noAssert=false)
Reads a signed 8 bit integer from the buffer at the specified offset.
buffer.readInt16LE(offset, noAssert=false)
buffer.readInt16BE(offset, noAssert=false)
buffer.readInt16BE(offset, noAssert=false)
Reads a signed 16 bit integer from the buffer at the specified offset with specified endian format.
buffer.readInt32LE(offset, noAssert=false)
buffer.readInt32BE(offset, noAssert=false)
buffer.readInt32BE(offset, noAssert=false)
Reads a signed 32 bit integer from the buffer at the specified offset with specified endian format.
buffer.readFloatLE(offset, noAssert=false)
buffer.readFloatBE(offset, noAssert=false)
buffer.readFloatBE(offset, noAssert=false)
Reads a 32 bit float from the buffer at the specified offset with specified endian format.
buffer.readDoubleLE(offset, noAssert=false)
buffer.readDoubleBE(offset, noAssert=false)
buffer.readDoubleBE(offset, noAssert=false)
Reads a 64 bit double from the buffer at the specified offset with specified endian format.
buffer.writeUInt8(value, offset, noAssert=false)
Writes value to the buffer at the specified offset. Note, value must be a valid unsigned 8 bit integer.
buffer.writeUInt16LE(value, offset, noAssert=false)
buffer.writeUInt16BE(value, offset, noAssert=false)
buffer.writeUInt16BE(value, offset, noAssert=false)
Writes value to the buffer at the specified offset with specified endian format. Note, value must be a valid unsigned 16 bit integer.
buffer.writeUInt32LE(value, offset, noAssert=false)
buffer.writeUInt32BE(value, offset, noAssert=false)
buffer.writeUInt32BE(value, offset, noAssert=false)
Writes value to the buffer at the specified offset with specified endian format. Note, value must be a valid unsigned 32 bit integer.
buffer.writeInt8(value, offset, noAssert=false)
Writes value to the buffer at the specified offset. Note, value must be a valid signed 8 bit integer.
buffer.writeInt16LE(value, offset, noAssert=false)
buffer.writeInt16BE(value, offset, noAssert=false)
buffer.writeInt16BE(value, offset, noAssert=false)
Writes value to the buffer at the specified offset with specified endian format. Note, value must be a valid signed 16 bit integer.
buffer.writeInt32LE(value, offset, noAssert=false)
buffer.writeInt32BE(value, offset, noAssert=false)
buffer.writeInt32BE(value, offset, noAssert=false)
Writes value to the buffer at the specified offset with specified endian format. Note, value must be a valid signed 32 bit integer.
buffer.writeFloatLE(value, offset, noAssert=false)
buffer.writeFloatBE(value, offset, noAssert=false)
buffer.writeFloatBE(value, offset, noAssert=false)
Writes value to the buffer at the specified offset with specified endian format. Note, value must be a valid 32 bit float.
buffer.writeDoubleLE(value, offset, noAssert=false)
buffer.writeDoubleBE(value, offset, noAssert=false)
buffer.writeDoubleBE(value, offset, noAssert=false)
Writes value to the buffer at the specified offset with specified endian format. Note, value must be a valid 64 bit double.
buffer.fill(value, offset=0, end=buffer.length)
Fills the buffer with the specified value. If the offset and end are not given it will fill the entire buffer.
INSPECT_MAX_BYTES
How many bytes will be returned when buffer.inspect() is called. This can be overriden by user modules.
Event: 'exit'
function (code, signal) {}
child.stdin
A Writable Stream that represents the child process's stdin. Closing this stream via end() often causes the child process to terminate.
child.stdout
A Readable Stream that represents the child process's stdout.
child.stderr
A Readable Stream that represents the child process's stderr.
child.pid
The PID of the child process.
child_process.spawn(command, args=[], [options])
Launches a new process with the given command, with command line arguments in args. If omitted, args defaults to an empty Array.
child_process.exec(command, [options], callback)
Runs a command in a shell and buffers the output.
child_process.execFile(file, args, options, callback)
This is similar to child_process.exec() except it does not execute a subshell but rather the specified file directly. This makes it slightly
leaner than child_process.exec. It has the same options.
child_process.fork(modulePath, arguments, options)
This is a special case of the spawn() functionality for spawning Node processes. In addition to having all the methods in a normal ChildProcess
instance, the returned object has a communication channel built-in. The
channel is written to with child.send(message, [sendHandle]) and messages
are recieved by a 'message' event on the child.
child.kill(signal='SIGTERM')
Send a signal to the child process. If no argument is given, the process will be sent 'SIGTERM'. See signal(7) for a list of available signals.
crypto.createCredentials(details)
Creates a credentials object, with the optional details being a dictionary with keys:
crypto.createHash(algorithm)
Creates and returns a hash object, a cryptographic hash with the given algorithm which can be used to generate hash digests.
hash.update(data)
Updates the hash content with the given data. This can be called many times with new data as it is streamed.
hash.digest(encoding='binary')
Calculates the digest of all of the passed data to be hashed. The encoding can be 'hex', 'binary' or 'base64'.
crypto.createHmac(algorithm, key)
Creates and returns a hmac object, a cryptographic hmac with the given algorithm and key.
hmac.update(data)
Update the hmac content with the given data. This can be called many times with new data as it is streamed.
hmac.digest(encoding='binary')
Calculates the digest of all of the passed data to the hmac. The encoding can be 'hex', 'binary' or 'base64'.
crypto.createCipher(algorithm, password)
Creates and returns a cipher object, with the given algorithm and password.
crypto.createCipheriv(algorithm, key, iv)
Creates and returns a cipher object, with the given algorithm, key and iv.
cipher.update(data, input_encoding='binary', output_encoding='binary')
Updates the cipher with data, the encoding of which is given in input_encoding and can be 'utf8', 'ascii' or 'binary'. The output_encoding specifies
the output format of the enciphered data, and can be 'binary', 'base64' or 'hex'.
cipher.final(output_encoding='binary')
Returns any remaining enciphered contents, with output_encoding being one of: 'binary', 'base64' or 'hex'.
crypto.createDecipher(algorithm, password)
Creates and returns a decipher object, with the given algorithm and key. This is the mirror of the createCipher() above.
crypto.createDecipheriv(algorithm, key, iv)
Creates and returns a decipher object, with the given algorithm, key and iv. This is the mirror of the createCipheriv() above.
decipher.update(data, input_encoding='binary', output_encoding='binary')
Updates the decipher with data, which is encoded in 'binary', 'base64' or 'hex'. The output_decoding specifies in what format to return the deciphered plaintext: 'binary', 'ascii' or 'utf8'.
decipher.final(output_encoding='binary')
Returns any remaining plaintext which is deciphered, with output_encoding being one of: 'binary', 'ascii' or 'utf8'.
crypto.createSign(algorithm)
Creates and returns a signing object, with the given algorithm. On recent OpenSSL releases, openssl list-public-key-algorithms will display
the available signing algorithms. Examples are 'RSA-SHA256'.
signer.update(data)
Updates the signer object with data. This can be called many times with new data as it is streamed.
signer.sign(private_key, output_format='binary')
Calculates the signature on all the updated data passed through the signer. private_key is a string containing the PEM encoded private key for signing.
crypto.createVerify(algorithm)
Creates and returns a verification object, with the given algorithm. This is the mirror of the signing object above.
verifier.update(data)
Updates the verifier object with data. This can be called many times with new data as it is streamed.
verifier.verify(object, signature, signature_format='binary')
Verifies the signed data by using the object and signature. object is a string containing a PEM encoded object, which can be one of RSA public key,
DSA public key, or X.509 certificate. signature is the previously calculated
signature for the data, in the signature_format which can be 'binary',
'hex' or 'base64'.
crypto.createDiffieHellman(prime_length)
Creates a Diffie-Hellman key exchange object and generates a prime of the given bit length. The generator used is 2.
crypto.createDiffieHellman(prime, encoding='binary')
Creates a Diffie-Hellman key exchange object using the supplied prime. The generator used is 2. Encoding can be 'binary', 'hex', or 'base64'.
diffieHellman.generateKeys(encoding='binary')
Generates private and public Diffie-Hellman key values, and returns the public key in the specified encoding. This key should be transferred to the
other party. Encoding can be 'binary', 'hex', or 'base64'.
diffieHellman.computeSecret(other_public_key, input_encoding='binary', output_encoding=input_encoding)
Computes the shared secret using other_public_key as the other party's public key and returns the computed shared secret. Supplied key is
interpreted using specified input_encoding, and secret is encoded using
specified output_encoding. Encodings can be 'binary', 'hex', or
'base64'. If no output encoding is given, the input encoding is used as
output encoding.
diffieHellman.getPrime(encoding='binary')
Returns the Diffie-Hellman prime in the specified encoding, which can be 'binary', 'hex', or 'base64'.
diffieHellman.getGenerator(encoding='binary')
Returns the Diffie-Hellman prime in the specified encoding, which can be 'binary', 'hex', or 'base64'.
diffieHellman.getPublicKey(encoding='binary')
Returns the Diffie-Hellman public key in the specified encoding, which can be 'binary', 'hex', or 'base64'.
diffieHellman.getPrivateKey(encoding='binary')
Returns the Diffie-Hellman private key in the specified encoding, which can be 'binary', 'hex', or 'base64'.
diffieHellman.setPublicKey(public_key, encoding='binary')
Sets the Diffie-Hellman public key. Key encoding can be 'binary', 'hex', or 'base64'.
diffieHellman.setPrivateKey(public_key, encoding='binary')
Sets the Diffie-Hellman private key. Key encoding can be 'binary', 'hex', or 'base64'.
pbkdf2(password, salt, iterations, keylen, callback)
Asynchronous PBKDF2 applies pseudorandom function HMAC-SHA1 to derive a key of given length from the given password, salt and iterations.
The callback gets two arguments (err, derivedKey).
randomBytes(size, [callback])
Generates cryptographically strong pseudo-random data. Usage:
Event: 'message'
function (msg, rinfo) { }
Event: 'listening'
function () { }
Event: 'close'
function () { }
Event: 'error'
function (exception) {}
dgram.createSocket(type, [callback])
Creates a datagram socket of the specified types. Valid types are udp4 and udp6.
dgram.send(buf, offset, length, port, address, [callback])
For UDP sockets, the destination port and IP address must be specified. A string may be supplied for the address parameter, and it will be resolved with DNS. An
optional callback may be specified to detect any DNS errors and when buf may be
re-used. Note that DNS lookups will delay the time that a send takes place, at
least until the next tick. The only way to know for sure that a send has taken place
is to use the callback.
dgram.bind(port, [address])
For UDP sockets, listen for datagrams on a named port and optional address. If address is not specified, the OS will try to listen on all addresses.
dgram.close()
Close the underlying socket and stop listening for data on it.
dgram.address()
Returns an object containing the address information for a socket. For UDP sockets, this object will contain address and port.
dgram.setBroadcast(flag)
Sets or clears the SO_BROADCAST socket option. When this option is set, UDP packets may be sent to a local interface's broadcast address.
dgram.setTTL(ttl)
Sets the IP_TTL socket option. TTL stands for "Time to Live," but in this context it specifies the number of IP hops that a packet is allowed to go through. Each router or
gateway that forwards a packet decrements the TTL. If the TTL is decremented to 0 by a
router, it will not be forwarded. Changing TTL values is typically done for network
probes or when multicasting.
dgram.setMulticastTTL(ttl)
Sets the IP_MULTICAST_TTL socket option. TTL stands for "Time to Live," but in this context it specifies the number of IP hops that a packet is allowed to go through,
specifically for multicast traffic. Each router or gateway that forwards a packet
decrements the TTL. If the TTL is decremented to 0 by a router, it will not be forwarded.
dgram.setMulticastLoopback(flag)
Sets or clears the IP_MULTICAST_LOOP socket option. When this option is set, multicast packets will also be received on the local interface.
dgram.addMembership(multicastAddress, [multicastInterface])
Tells the kernel to join a multicast group with IP_ADD_MEMBERSHIP socket option.
dgram.dropMembership(multicastAddress, [multicastInterface])
Opposite of addMembership - tells the kernel to leave a multicast group with IP_DROP_MEMBERSHIP socket option. This is automatically called by the kernel
when the socket is closed or process terminates, so most apps will never need to call
this.
dns.lookup(domain, family=null, callback)
Resolves a domain (e.g. 'google.com') into the first found A (IPv4) or AAAA (IPv6) record.
dns.resolve(domain, rrtype='A', callback)
Resolves a domain (e.g. 'google.com') into an array of the record types specified by rrtype. Valid rrtypes are A (IPV4 addresses), AAAA (IPV6
addresses), MX (mail exchange records), TXT (text records), SRV (SRV
records), PTR (used for reverse IP lookups), NS (name server records)
and CNAME (canonical name records).
dns.resolve4(domain, callback)
The same as dns.resolve(), but only for IPv4 queries (A records). addresses is an array of IPv4 addresses (e.g.
['74.125.79.104', '74.125.79.105', '74.125.79.106']).
dns.resolve6(domain, callback)
The same as dns.resolve4() except for IPv6 queries (an AAAA query).
dns.resolveMx(domain, callback)
The same as dns.resolve(), but only for mail exchange queries (MX records).
dns.resolveTxt(domain, callback)
The same as dns.resolve(), but only for text queries (TXT records). addresses is an array of the text records available for domain (e.g.,
['v=spf1 ip4:0.0.0.0 ~all']).
dns.resolveSrv(domain, callback)
The same as dns.resolve(), but only for service records (SRV records). addresses is an array of the SRV records available for domain. Properties
of SRV records are priority, weight, port, and name (e.g.,
[{'priority': 10, {'weight': 5, 'port': 21223, 'name': 'service.example.com'}, ...]).
dns.reverse(ip, callback)
Reverse resolves an ip address to an array of domain names.
dns.resolveNs(domain, callback)
The same as dns.resolve(), but only for name server records (NS records). addresses is an array of the name server records available for domain
(e.g., ['ns1.example.com', 'ns2.example.com']).
dns.resolveCname(domain, callback)
The same as dns.resolve(), but only for canonical name records (CNAME records). addresses is an array of the canonical name records available for
domain (e.g., ['bar.example.com']).
fs.rename(path1, path2, [callback])
Asynchronous rename(2). No arguments other than a possible exception are given to the completion callback.
fs.renameSync(path1, path2)
Synchronous rename(2).
fs.truncate(fd, len, [callback])
Asynchronous ftruncate(2). No arguments other than a possible exception are given to the completion callback.
fs.truncateSync(fd, len)
Synchronous ftruncate(2).
fs.chown(path, uid, gid, [callback])
Asynchronous chown(2). No arguments other than a possible exception are given to the completion callback.
fs.chownSync(path, uid, gid)
Synchronous chown(2).
fs.fchown(fd, uid, gid, [callback])
Asynchronous fchown(2). No arguments other than a possible exception are given to the completion callback.
fs.fchownSync(fd, uid, gid)
Synchronous fchown(2).
fs.lchown(path, uid, gid, [callback])
Asynchronous lchown(2). No arguments other than a possible exception are given to the completion callback.
fs.lchownSync(path, uid, gid)
Synchronous lchown(2).
fs.chmod(path, mode, [callback])
Asynchronous chmod(2). No arguments other than a possible exception are given to the completion callback.
fs.chmodSync(path, mode)
Synchronous chmod(2).
fs.fchmod(fd, mode, [callback])
Asynchronous fchmod(2). No arguments other than a possible exception are given to the completion callback.
fs.fchmodSync(fd, mode)
Synchronous fchmod(2).
fs.lchmod(path, mode, [callback])
Asynchronous lchmod(2). No arguments other than a possible exception are given to the completion callback.
fs.lchmodSync(path, mode)
Synchronous lchmod(2).
fs.stat(path, [callback])
Asynchronous stat(2). The callback gets two arguments (err, stats) where stats is a fs.Stats object. See the fs.Stats
section below for more information.
fs.lstat(path, [callback])
Asynchronous lstat(2). The callback gets two arguments (err, stats) where stats is a fs.Stats object. lstat() is identical to stat(), except that if
path is a symbolic link, then the link itself is stat-ed, not the file that it
refers to.
fs.fstat(fd, [callback])
Asynchronous fstat(2). The callback gets two arguments (err, stats) where stats is a fs.Stats object. fstat() is identical to stat(), except that
the file to be stat-ed is specified by the file descriptor fd.
fs.statSync(path)
Synchronous stat(2). Returns an instance of fs.Stats.
fs.lstatSync(path)
Synchronous lstat(2). Returns an instance of fs.Stats.
fs.fstatSync(fd)
Synchronous fstat(2). Returns an instance of fs.Stats.
fs.link(srcpath, dstpath, [callback])
Asynchronous link(2). No arguments other than a possible exception are given to the completion callback.
fs.linkSync(srcpath, dstpath)
Synchronous link(2).
fs.symlink(linkdata, path, [callback])
Asynchronous symlink(2). No arguments other than a possible exception are given to the completion callback.
fs.symlinkSync(linkdata, path)
Synchronous symlink(2).
fs.readlink(path, [callback])
Asynchronous readlink(2). The callback gets two arguments (err, linkString).
fs.readlinkSync(path)
Synchronous readlink(2). Returns the symbolic link's string value.
fs.realpath(path, [callback])
Asynchronous realpath(2). The callback gets two arguments (err, resolvedPath). May use process.cwd to resolve relative paths.
fs.realpathSync(path)
Synchronous realpath(2). Returns the resolved path.
fs.unlink(path, [callback])
Asynchronous unlink(2). No arguments other than a possible exception are given to the completion callback.
fs.unlinkSync(path)
Synchronous unlink(2).
fs.rmdir(path, [callback])
Asynchronous rmdir(2). No arguments other than a possible exception are given to the completion callback.
fs.rmdirSync(path)
Synchronous rmdir(2).
fs.mkdir(path, [mode], [callback])
Asynchronous mkdir(2). No arguments other than a possible exception are given to the completion callback. mode defaults to 0777.
fs.mkdirSync(path, [mode])
Synchronous mkdir(2).
fs.readdir(path, [callback])
Asynchronous readdir(3). Reads the contents of a directory. The callback gets two arguments (err, files) where files is an array of
the names of the files in the directory excluding '.' and '..'.
fs.readdirSync(path)
Synchronous readdir(3). Returns an array of filenames excluding '.' and '..'.
fs.close(fd, [callback])
Asynchronous close(2). No arguments other than a possible exception are given to the completion callback.
fs.closeSync(fd)
Synchronous close(2).
fs.open(path, flags, [mode], [callback])
Asynchronous file open. See open(2). flags can be:
fs.openSync(path, flags, [mode])
Synchronous open(2).
fs.utimes(path, atime, mtime, [callback])
fs.utimesSync(path, atime, mtime)
fs.utimesSync(path, atime, mtime)
Change file timestamps of the file referenced by the supplied path.
fs.futimes(fd, atime, mtime, [callback])
fs.futimesSync(fd, atime, mtime)
fs.futimesSync(fd, atime, mtime)
Change the file timestamps of a file referenced by the supplied file descriptor.
fs.fsync(fd, [callback])
Asynchronous fsync(2). No arguments other than a possible exception are given to the completion callback.
fs.fsyncSync(fd)
Synchronous fsync(2).
fs.write(fd, buffer, offset, length, position, [callback])
Write buffer to the file specified by fd.
fs.writeSync(fd, buffer, offset, length, position)
Synchronous version of buffer-based fs.write(). Returns the number of bytes written.
fs.writeSync(fd, str, position, encoding='utf8')
Synchronous version of string-based fs.write(). Returns the number of bytes written.
fs.read(fd, buffer, offset, length, position, [callback])
Read data from the file specified by fd.
fs.readSync(fd, buffer, offset, length, position)
Synchronous version of buffer-based fs.read. Returns the number of bytesRead.
fs.readSync(fd, length, position, encoding)
Synchronous version of string-based fs.read. Returns the number of bytesRead.
fs.readFile(filename, [encoding], [callback])
Asynchronously reads the entire contents of a file. Example:
fs.readFileSync(filename, [encoding])
Synchronous version of fs.readFile. Returns the contents of the filename.
fs.writeFile(filename, data, encoding='utf8', [callback])
Asynchronously writes data to a file, replacing the file if it already exists. data can be a string or a buffer. The encoding argument is ignored if
data is a buffer.
fs.writeFileSync(filename, data, encoding='utf8')
The synchronous version of fs.writeFile.
fs.watchFile(filename, [options], listener)
Watch for changes on filename. The callback listener will be called each time the file is accessed.
fs.unwatchFile(filename)
Stop watching for changes on filename.
fs.watch(filename, [options], listener)
Watch for changes on filename, where filename is either a file or a directory. The returned object is fs.FSWatcher.
Event: 'open'
function (fd) { }
fs.createReadStream(path, [options])
Returns a new ReadStream object (See Readable Stream).
Event: 'open'
function (fd) { }
file.bytesWritten
The number of bytes written so far. Does not include data that is still queued for writing.
fs.createWriteStream(path, [options])
Returns a new WriteStream object (See Writable Stream).
Event: 'request'
function (request, response) { }
Event: 'connection'
function (socket) { }
Event: 'close'
function () { }
Event: 'checkContinue'
function (request, response) { }
Event: 'upgrade'
function (request, socket, head) { }
Event: 'clientError'
function (exception) { }
http.createServer([requestListener])
Returns a new web server object.
server.listen(port, [hostname], [callback])
Begin accepting connections on the specified port and hostname. If the hostname is omitted, the server will accept connections directed to any
IPv4 address (INADDR_ANY).
server.listen(path, [callback])
Start a UNIX socket server listening for connections on the given path.
server.close()
Stops the server from accepting new connections.
Event: 'data'
function (chunk) { }
Event: 'end'
function () { }
Event: 'close'
function () { }
request.method
The request method as a string. Read only. Example: 'GET', 'DELETE'.
request.url
Request URL string. This contains only the URL that is present in the actual HTTP request. If the request is:
request.headers
Read only.
request.trailers
Read only; HTTP trailers (if present). Only populated after the 'end' event.
request.httpVersion
The HTTP protocol version as a string. Read only. Examples: '1.1', '1.0'.
Also request.httpVersionMajor is the first integer and
request.httpVersionMinor is the second.
request.setEncoding(encoding=null)
Set the encoding for the request body. Either 'utf8' or 'binary'. Defaults to null, which means that the 'data' event will emit a Buffer object..
request.pause()
Pauses request from emitting events. Useful to throttle back an upload.
request.resume()
Resumes a paused request.
request.connection
The net.Socket object associated with the connection.
response.writeContinue()
Sends a HTTP/1.1 100 Continue message to the client, indicating that the request body should be sent. See the checkContinue event on
Server.
response.writeHead(statusCode, [reasonPhrase], [headers])
Sends a response header to the request. The status code is a 3-digit HTTP status code, like 404. The last argument, headers, are the response headers.
Optionally one can give a human-readable reasonPhrase as the second
argument.
response.statusCode
When using implicit headers (not calling response.writeHead() explicitly), this property controls the status code that will be send to the client when the headers get
flushed.
response.setHeader(name, value)
Sets a single header value for implicit headers. If this header already exists in the to-be-sent headers, its value will be replaced. Use an array of strings
here if you need to send multiple headers with the same name.
response.getHeader(name)
Reads out a header that's already been queued but not sent to the client. Note that the name is case insensitive. This can only be called before headers get
implicitly flushed.
response.removeHeader(name)
Removes a header that's queued for implicit sending.
response.write(chunk, encoding='utf8')
If this method is called and response.writeHead() has not been called, it will switch to implicit header mode and flush the implicit headers.
response.addTrailers(headers)
This method adds HTTP trailing headers (a header but at the end of the message) to the response.
response.end([data], [encoding])
This method signals to the server that all of the response headers and body has been sent; that server should consider this message complete.
The method, response.end(), MUST be called on each
response.
agent.maxSockets
By default set to 5. Determines how many concurrent sockets the agent can have open per host.
agent.sockets
An object which contains arrays of sockets currently in use by the Agent. Do not modify.
agent.requests
An object which contains queues of requests that have not yet been assigned to sockets. Do not modify.
Event 'response'
function (response) { }
Event: 'socket'
function (socket) { }
Event: 'upgrade'
function (response, socket, head) { }
Event: 'continue'
function ()
request.write(chunk, encoding='utf8')
Sends a chunk of the body. By calling this method many times, the user can stream a request body to a
server--in that case it is suggested to use the
['Transfer-Encoding', 'chunked'] header line when
creating the request.
request.end([data], [encoding])
Finishes sending the request. If any parts of the body are unsent, it will flush them to the stream. If the request is
chunked, this will send the terminating '0\r\n\r\n'.
request.abort()
Aborts a request. (New since v0.3.8.)
request.setTimeout(timeout, [callback])
Once a socket is assigned to this request and is connected socket.setTimeout(timeout, [callback])
will be called.
request.setNoDelay(noDelay=true)
Once a socket is assigned to this request and is connected socket.setNoDelay(noDelay)
will be called.
request.setSocketKeepAlive(enable=false, [initialDelay])
Once a socket is assigned to this request and is connected socket.setKeepAlive(enable, [initialDelay])
will be called.
Event: 'data'
function (chunk) { }
Event: 'end'
function () { }
Event: 'close'
function (err) { }
response.statusCode
The 3-digit HTTP response status code. E.G. 404.
response.httpVersion
The HTTP version of the connected-to server. Probably either '1.1' or '1.0'.
Also response.httpVersionMajor is the first integer and
response.httpVersionMinor is the second.
response.headers
The response headers object.
response.trailers
The response trailers object. Only populated after the 'end' event.
response.setEncoding(encoding=null)
Set the encoding for the response body. Either 'utf8', 'ascii', or 'base64'. Defaults to null, which means that the 'data' event will emit a Buffer object..
response.pause()
Pauses response from emitting events. Useful to throttle back a download.
response.resume()
Resumes a paused response.
Cycles
When there are circular require() calls, a module might not be done being executed when it is returned.
Core Modules
Node has several modules compiled into the binary. These modules are described in greater detail elsewhere in this documentation.
File Modules
If the exact filename is not found, then node will attempt to load the required filename with the added extension of .js, .json, and then .node.
Loading from `node_modules` Folders
If the module identifier passed to require() is not a native module, and does not begin with '/', '../', or './', then node starts at the
parent directory of the current module, and adds /node_modules, and
attempts to load the module from that location.
Folders as Modules
It is convenient to organize programs and libraries into self-contained directories, and then provide a single entry point to that library.
There are three ways in which a folder may be passed to require() as
an argument.
Caching
Modules are cached after the first time they are loaded. This means (among other things) that every call to require('foo') will get
exactly the same object returned, if it would resolve to the same file.
module.exports
The 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. For example suppose we
were making a module called a.js
module.require
The module.require method provides a way to load a module as if require() was called from the original module.
All Together...
To get the exact filename that will be loaded when require() is called, use the require.resolve() function.
Loading from the global folders
If the NODE_PATH environment variable is set to a colon-delimited list of absolute paths, then node will search those paths for modules if they
are not found elsewhere. (Note: On Windows, NODE_PATH is delimited by
semicolons instead of colons.)
Accessing the main module
When a file is run directly from Node, require.main is set to its module. That means that you can determine whether a file has been run
directly by testing
Event: 'exit'
function () {}
Event: 'uncaughtException'
function (err) { }
Signal Events
function () {}
process.stdout
A Writable Stream to stdout.
process.stderr
A writable stream to stderr.
process.stdin
A Readable Stream for stdin. The stdin stream is paused by default, so one must call process.stdin.resume() to read from it.
process.argv
An array containing the command line arguments. The first element will be 'node', the second element will be the name of the JavaScript file. The
next elements will be any additional command line arguments.
process.execPath
This is the absolute pathname of the executable that started the process.
process.chdir(directory)
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.env
An object containing the user environment. See environ(7).
process.exit(code=0)
Ends the process with the specified code. If omitted, exit uses the 'success' code 0.
process.getgid()
Gets the group identity of the process. (See getgid(2).) This is the numerical group id, not the group name.
process.setgid(id)
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.
process.getuid()
Gets the user identity of the process. (See getuid(2).) This is the numerical userid, not the username.
process.setuid(id)
Sets the user identity of the process. (See setuid(2).) This accepts either a numerical ID or a username string. If a username is specified, this method
blocks while resolving it to a numerical ID.
process.version
A compiled-in property that exposes NODE_VERSION.
process.versions
A property exposing version strings of node and its dependencies.
process.installPrefix
A compiled-in property that exposes NODE_PREFIX.
process.kill(pid, signal='SIGTERM')
Send a signal to a process. pid is the process id and signal is the string describing the signal to send. Signal names are strings like
'SIGINT' or 'SIGUSR1'. If omitted, the signal will be 'SIGTERM'.
See kill(2) for more information.
process.pid
The PID of the process.
process.title
Getter/setter to set what is displayed in 'ps'.
process.arch
What processor architecture you're running on: 'arm', 'ia32', or 'x64'.
process.platform
What platform you're running on. 'linux2', 'darwin', etc.
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. This is not a simple alias to setTimeout(fn, 0), it's much more
efficient.
process.umask([mask])
Sets or reads the process's file mode creation mask. Child processes inherit the mask from the parent process. Returns the old mask if mask argument is
given, otherwise returns the current mask.
process.uptime()
Number of seconds Node has been running.
rl.createInterface(input, output, completer)
Takes two streams and creates a readline interface. The completer function is used for autocompletion. When given a substring, it returns [[substr1,
substr2, ...], originalsubstring].
rl.setPrompt(prompt, length)
Sets the prompt, for example when you run node on the command line, you see >, which is node's prompt.
rl.prompt()
Readies readline for input from the user, putting the current setPrompt options on a new line, giving the user a new spot to write.
rl.question(query, callback)
Prepends the prompt with query and invokes callback with the user's response. Displays the query to the user, and then invokes callback with the
user's response after it has been typed.
rl.close()
Closes tty.
rl.pause()
Pauses tty.
rl.resume()
Resumes tty.
rl.write()
Writes to tty.
Event: 'line'
function (line) {}
Event: 'close'
function () {}
Event: 'data'
function (data) { }
Event: 'end'
function () { }
Event: 'error'
function (exception) { }
Event: 'close'
function () { }
stream.readable
A boolean that is true by default, but turns false after an 'error' occurred, the stream came to an 'end', or destroy() was called.
stream.setEncoding(encoding)
Makes the data event emit a string instead of a Buffer. encoding can be 'utf8', 'ascii', or 'base64'.
stream.pause()
Pauses the incoming 'data' events.
stream.resume()
Resumes the incoming 'data' events after a pause().
stream.destroy()
Closes the underlying file descriptor. Stream will not emit any more events.
stream.destroySoon()
After the write queue is drained, close the file descriptor.
stream.pipe(destination, [options])
This is a Stream.prototype method available on all Streams.
Event: 'drain'
function () { }
Event: 'error'
function (exception) { }
Event: 'close'
function () { }
Event: 'pipe'
function (src) { }
stream.writable
A boolean that is true by default, but turns false after an 'error' occurred or end() / destroy() was called.
stream.write(string, encoding='utf8', [fd])
Writes string with the given encoding to the stream. Returns true if the string has been flushed to the kernel buffer. Returns false to
indicate that the kernel buffer is full, and the data will be sent out in
the future. The 'drain' event will indicate when the kernel buffer is
empty again. The encoding defaults to 'utf8'.
stream.write(buffer)
Same as the above except with a raw buffer.
stream.end()
Terminates the stream with EOF or FIN. This call will allow queued write data to be sent before closing the stream.
stream.end(string, encoding)
Sends string with the given encoding and terminates the stream with EOF or FIN. This is useful to reduce the number of packets sent.
stream.end(buffer)
Same as above but with a buffer.
stream.destroy()
Closes the underlying file descriptor. Stream will not emit any more events. Any queued write data will not be sent.
stream.destroySoon()
After the write queue is drained, close the file descriptor. destroySoon() can still destroy straight away, as long as there is no data left in the queue
for writes.
vm.runInThisContext(code, [filename])
vm.runInThisContext() compiles code as if it were loaded from filename, runs it and returns the result. Running code does not have access to local scope. filename is optional.
vm.runInNewContext(code, [sandbox], [filename])
vm.runInNewContext compiles code to run in sandbox as if it were loaded from filename, then runs it and returns the result. Running code does not have access to local scope and
the object sandbox will be used as the global object for code.
sandbox and filename are optional.
vm.runInContext(code, context, [filename])
vm.runInContext compiles code to run in context context as if it were loaded from filename, then runs it and returns the result. A (V8) context comprises a global object, together with a
set of built-in objects and functions. Running code does not have access to local scope and
the global object held within context will be used as the global object for code.
filename is optional.
vm.createContext([initSandbox])
vm.createContext creates a new context which is suitable for use as the 2nd argument of a subsequent call to vm.runInContext. A (V8) context comprises a global object together with a set of
build-in objects and functions. The optional argument initSandbox will be shallow-copied
to seed the initial contents of the global object used by the context.
vm.createScript(code, [filename])
createScript compiles code as if it were loaded from filename, but does not run it. Instead, it returns a vm.Script object representing this compiled code.
This script can be run later many times using methods below.
The returned script is not bound to any global object.
It is bound before each run, just for that run. filename is optional.
script.runInThisContext()
Similar to vm.runInThisContext but a method of a precompiled Script object. script.runInThisContext runs the code of script and returns the result.
Running code does not have access to local scope, but does have access to the global object
(v8: in actual context).
script.runInNewContext([sandbox])
Similar to vm.runInNewContext a method of a precompiled Script object. script.runInNewContext runs the code of script with sandbox as the global object and returns the result.
Running code does not have access to local scope. sandbox is optional.
Examples
Compressing or decompressing a file can be done by piping an fs.ReadStream into a zlib stream, then into an fs.WriteStream.
Constants
All of the constants defined in zlib.h are also defined on require('zlib'). They are described in more detail in the zlib
documentation. See http://zlib.net/manual.html#Constants
for more details.
zlib.createGzip([options])
Returns a new Gzip object with an options.
zlib.createGunzip([options])
Returns a new Gunzip object with an options.
zlib.createDeflate([options])
Returns a new Deflate object with an options.
zlib.createInflate([options])
Returns a new Inflate object with an options.
zlib.createDeflateRaw([options])
Returns a new DeflateRaw object with an options.
zlib.createInflateRaw([options])
Returns a new InflateRaw object with an options.
zlib.createUnzip([options])
Returns a new Unzip object with an options.
zlib.Gzip
Compress data using gzip.
zlib.Gunzip
Decompress a gzip stream.
zlib.Deflate
Compress data using deflate.
zlib.Inflate
Decompress a deflate stream.
zlib.DeflateRaw
Compress data using deflate, and do not append a zlib header.
zlib.InflateRaw
Decompress a raw deflate stream.
zlib.Unzip
Decompress either a Gzip- or Deflate-compressed stream by auto-detecting the header.
zlib.deflate(buf, callback)
Compress a string with Deflate.
zlib.deflateRaw(buf, callback)
Compress a string with DeflateRaw.
zlib.gzip(buf, callback)
Compress a string with Gzip.
zlib.gunzip(buf, callback)
Decompress a raw Buffer with Gunzip.
zlib.inflate(buf, callback)
Decompress a raw Buffer with Inflate.
zlib.inflateRaw(buf, callback)
Decompress a raw Buffer with InflateRaw.
zlib.unzip(buf, callback)
Decompress a raw Buffer with Unzip.
Memory Usage Tuning
From zlib/zconf.h, modified to node's usage: