Cheat-Sheet-Raw
Vanilla JS
Object.length(obj);length is a property of a function object, and indicates how many arguments the function expects, i.e. the number of formal parameters. This number does not include the rest parameter. Has a value of 1
Object.prototype;Represents the Object prototype object and allows to add new properties and methods to all objects of type Object
Object.assign(target, ...sources);Copies the values of all enumerable own properties from one or more source objects to a target object. method is used to copy the values of all enumerable own properties from one or more source objects to a target object. It will return the target object
Object.create(MyObject);Creates a new object with the specified prototype object and properties. The object which should be the prototype of the newly-created object
Object.defineProperty(obj, prop, descriptor);Adds the named property described by a given descriptor to an object
Adds the named properties described by the given descriptors to an object
Returns an array containing all of the [key, value] pairs of a given object's own enumerable string properties
Freezes an object: other code can't delete or change any properties
Returns a property descriptor for a named property on an object
Returns an object containing all own property descriptors for an object
Returns an array containing the names of all of the given object's own enumerable and non-enumerable properties
Returns an array of all symbol properties found directly upon a given object
Returns the prototype of the specified object
Compares if two values are the same value. Equates all NaN values (which differs from both Abstract Equality Comparison and Strict Equality Comparison)
Determines if extending of an object is allowed
Determines if an object was frozen
Determines if an object is sealed
Returns an array containing the names of all of the given object's own enumerable string properties
Prevents any extensions of an object
Prevents other code from deleting properties of an object
Sets the prototype (i.e., the internal [[Prototype]] property)
Returns an array containing the values that correspond to all of a given object's own enumerable string properties
Specifies the function that creates an object's prototype
Points to the object which was used as prototype when the object was instantiated
Returns a boolean indicating whether an object contains the specified property as a direct property of that object and not inherited through the prototype chain
Returns a boolean indicating whether the object this method is called upon is in the prototype chain of the specified object
Returns a boolean indicating if the internal ECMAScript [[Enumerable]] attribute is set
Calls toString()
Returns a string representation of the object
Returns the primitive value of the specified object
Global object: properties
Reflects the number of elements in an array
Represents the prototype for the Array constructor and allows to add new properties and methods to all Array objects
Global object: methods
Creates a new Array instance from an array-like or iterable object
Returns true if a variable is an array, if not false
Creates a new Array instance with a variable number of arguments, regardless of number or type of the arguments
Reflects the number of elements in an array
Copies a sequence of array elements within the array
Fills all the elements of an array from a start index to an end index with a static value
Removes the last element from an array and returns that element
Adds one or more elements to the end of an array and returns the new length of the array
Reverses the order of the elements of an array in place โ the first becomes the last, and the last becomes the first
Removes the first element from an array and returns that element
Sorts the elements of an array in place and returns the array
Adds one or more elements to the front of an array and returns the new length of the array
Returns a new array comprised of this array joined with other array(s) and/or value(s)
Determines whether an array contains a certain element, returning true or false as appropriate
Returns the first (least) index of an element within the array equal to the specified value, or -1 if none is found
Joins all elements of an array into a string
Returns the last (greatest) index of an element within the array equal to the specified value, or -1 if none is found
Extracts a section of an array and returns a new array
Returns a string representing the array and its elements. Overrides the Object.prototype.toString() method
Returns a localized string representing the array and its elements. Overrides the Object.prototype.toLocaleString() method
Returns a new Array Iterator object that contains the key/value pairs for each index in the array
Returns true if every element in this array satisfies the provided testing function
Creates a new array with all of the elements of this array for which the provided filtering function returns true
Returns the found value in the array, if an element in the array satisfies the provided testing function or undefined if not found
Returns the found index in the array, if an element in the array satisfies the provided testing function or -1 if not found
Calls a function for each element in the array
Returns a new Array Iterator that contains the keys for each index in the array
Creates a new array with the results of calling a provided function on every element in this array
Apply a function against an accumulator and each value of the array (from left-to-right) as to reduce it to a single value
Apply a function against an accumulator and each value of the array (from right-to-left) as to reduce it to a single value
Returns true if at least one element in this array satisfies the provided testing function
Returns a new Array Iterator object that contains the values for each index in the array
NodeJS
An example of a web server written with Node which responds with 'Hello World'
GLOBAL OBJECTS
In browsers, the top-level scope is the global scope
The filename of the code being executed. (absolute path)
A reference to the current module. In particular module.exports is used for defining what a module exports and makes available through require()
A reference to the module.exports that is shorter to type
The process object is a global object and can be accessed from anywhere. It is an instance of EventEmitter
The Buffer class is a global type for dealing with binary data directly
Prints to stdout with newline
Same as console.log but prints to stderr
Same as console.error
Uses util.inspect on obj and prints resulting string to stdout
Mark a time
Finish timer, record output
Print a stack trace to stderr of the current position
Same as assert.ok() where if the expression evaluates as false throw an AssertionError with message
To schedule execution of a one-time callback after delay milliseconds. Optionally you can also pass arguments to the callback
Stop a timer that was previously created with setTimeout()
To schedule the repeated execution of callback every delay milliseconds. Optionally you can also pass arguments to the callback
Stop a timer that was previously created with setInterval()
To schedule the "immediate" execution of callback after I/O events callbacks and before setTimeout and setInterval
Stop a timer that was previously created with setImmediate()
Allow you to create a timer that is active but if it is the only item left in the event loop, node won't keep the program running
If you had previously unref()d a timer you can call ref() to explicitly request the timer hold the program open
load another_module as if require() was called from the module itself
The identifier for the module. Typically this is the fully resolved filename
The fully resolved filename to the module
Whether or not the module is done loading, or is in the process of loading
The module that required this one
The module objects required by this one
If you want the root of your module's export to be a function (such as a constructor)
Emitted when the process is about to exit
A writable stream to stdout
A writable stream to stderr
A readable stream for stdin
An array containing the command line arguments
An object containing the user environment
This is the absolute pathname of the executable that started the process
This is the set of node-specific command line options from the executable that started the process
What processor architecture you're running on: 'arm', 'ia32', or 'x64'
An Object containing the JavaScript representation of the configure options that were used to compile the current node executable
The PID of the process
What platform you're running on: 'darwin', 'freebsd', 'linux', 'sunos' or 'win32'
Getter/setter to set what is displayed in 'ps'
A compiled-in property t
A property exposing version strings of node and its dependencies
This causes node to emit an abort. This will cause node to exit and generate a core file
Changes the current working directory of the process or throws an exception if that fails
Returns the current working directory of the process
Gets the group identity of the process
Sets the group identity of the process
Gets the user identity of the process
Sets the user identity of the process
Returns an array with the supplementary group IDs
Sets the supplementary group IDs
Reads /etc/group and initializes the group access list, using all groups of which the user is a member
Send a signal to a process. pid is the process id and signal is the string describing the signal to send
Returns an object describing the memory usage of the Node process measured in bytes
On the next loop around the event loop call this callback
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
Sets or reads the process's file mode creation mask
Number of seconds Node has been running
Returns the current high-resolution real time in a [seconds, nanoseconds] tuple Array
Class. ChildProcess is an EventEmitter
A Writable Stream that represents the child process's stdin
A Readable Stream that represents the child process's stderr
The PID of the child process
Send a signal to the child process
When using child_process.fork() you can write to the child using child.send(message, [sendHandle]) and messages are received by a 'message' event on the child
Close the IPC channel between parent and child, allowing the child to exit gracefully once there are no other connections keeping it alive
Launches a new process with the given command, with command line arguments in args. If omitted, args defaults to an empty Array
Runs a command in a shell and buffers the output
Runs a command in a shell and buffers the output
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
Returns a formatted string using the first argument as a printf-like format. (%s, %d, %j)
A synchronous output function. Will block the process and output string immediately to stderr
Same as util.debug() except this will output all arguments immediately to stderr
A synchronous output function. Will block the process and output all arguments to stdout with newlines after each argument
A synchronous output function. Will block the process, cast each argument to a string then output to stdout. (no newlines)
Return a string representation of object, which is useful for debugging. (options: showHidden, depth, colors, customInspect)
Returns true if the given "object" is a RegExp. false otherwise
Returns true if the given "object" is a Date. false otherwise
Returns true if the given "object" is an Error. false otherwise
Takes a function whose last argument is a callback and returns a version that returns promises
Inherit the prototype methods from one constructor into another
EVENTS
To access the EventEmitter class, require('events').EventEmitter
Adds a listener to the end of the listeners array for the specified event
Same as emitter.addListener()
Remove a listener from the listener array for the specified event
Removes all listeners, or those of the specified event
By default EventEmitters will print a warning if more than 10 listeners are added for a particular event
Returns an array of listeners for the specified event
Execute each of the listeners in order with the supplied arguments. Returns true if event had listeners, false otherwise
Return the number of listeners for a given event
When a chunk of data can be read from the stream, it will emit a 'readable' event
If you attach a data event listener, then it will switch the stream into flowing mode, and data will be passed to your handler as soon as it is available
This event fires when there will be no more data to read
Emitted when the underlying resource (for example, the backing file descriptor) has been closed. Not all streams will emit this
Emitted if there was an error receiving data
Call this function to cause the stream to return strings of the specified encoding instead of Buffer objects
This method will cause the readable stream to resume emitting data events
This method will cause a stream in flowing-mode to stop emitting data events
This method pulls all the data out of a readable stream, and writes it to the supplied destination, automatically managing the flow so that the destination is not overwhelmed by a fast readable stream
This method will remove the hooks set up for a previous pipe() call. If the destination is not specified, then all pipes are removed
This is useful in certain cases where a stream is being consumed by a parser, which needs to "un-consume" some data that it has optimistically pulled out of the source, so that the stream can be passed on to some other party
This method writes some data to the underlying system, and calls the supplied callback once the data has been fully handled
If a writable.write(chunk) call returns false, then the drain event will indicate when it is appropriate to begin writing more data to the stream
Call this method when no more data will be written to the stream
When the end() method has been called, and all data has been flushed to the underlying system, this event is emitted
This is emitted whenever the pipe() method is called on a readable stream, adding this writable to its set of destinations
This is emitted whenever the unpipe() method is called on a readable stream, removing this writable from its set of destinations
Emitted if there was an error when writing or piping data
To use this module do require('fs')
Asynchronous rename. No arguments other than a possible exception are given to the completion callback.Asynchronous ftruncate. No arguments other than a possible exception are given to the completion callback
Synchronous rename
Asynchronous ftruncate. No arguments other than a possible exception are given to the completion callback
Synchronous ftruncate
Asynchronous truncate. No arguments other than a possible exception are given to the completion callback
Synchronous truncate
Asynchronous chown. No arguments other than a possible exception are given to the completion callback
Synchronous chown
Asynchronous fchown. No arguments other than a possible exception are given to the completion callback
Synchronous fchown
Asynchronous lchown. No arguments other than a possible exception are given to the completion callback
Synchronous lchown
Asynchronous chmod. No arguments other than a possible exception are given to the completion callback
Synchronous chmod
Asynchronous fchmod. No arguments other than a possible exception are given to the completion callback
Synchronous fchmod
Asynchronous lchmod. No arguments other than a possible exception are given to the completion callback
Synchronous lchmod
Asynchronous stat. The callback gets two arguments (err, stats) where stats is a fs.Stats object
Synchronous stat. Returns an instance of fs.Stats
Asynchronous lstat. 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
Synchronous lstat. Returns an instance of fs.Stats
Asynchronous fstat. 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
Synchronous fstat. Returns an instance of fs.Stats
Asynchronous link. No arguments other than a possible exception are given to the completion callback
Synchronous link
Asynchronous symlink. No arguments other than a possible exception are given to the completion callback. The type argument can be set to 'dir', 'file', or 'junction' (default is 'file') and is only available on Windows (ignored on other platforms)
Synchronous symlink
Asynchronous readlink. The callback gets two arguments (err, linkString)
Synchronous readlink. Returns the symbolic link's string value
Asynchronous unlink. No arguments other than a possible exception are given to the completion callback
Synchronous unlink
Asynchronous realpath. The callback gets two arguments (err, resolvedPath)
Synchronous realpath. Returns the resolved path
Asynchronous rmdir. No arguments other than a possible exception are given to the completion callback
Synchronous rmdir
Asynchronous mkdir. No arguments other than a possible exception are given to the completion callback. mode defaults to 0777
Synchronous mkdir
Asynchronous readdir. 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 '..'
Synchronous readdir. Returns an array of filenames excluding '.' and '..'
Asynchronous close. No arguments other than a possible exception are given to the completion callback
Synchronous close
Asynchronous file open
Synchronous version of fs.open()
Change file timestamps of the file referenced by the supplied path
Synchronous version of fs.utimes()
Change the file timestamps of a file referenced by the supplied file descriptor
Synchronous version of fs.futimes()
Asynchronous fsync. No arguments other than a possible exception are given to the completion callback
Synchronous fsync
Write buffer to the file specified by fd
Synchronous version of fs.write(). Returns the number of bytes written
Read data from the file specified by fd
Synchronous version of fs.read. Returns the number of bytesRead
Asynchronously reads the entire contents of a file
Synchronous version of fs.readFile. Returns the contents of the filename. If the encoding option is specified then this function returns a string. Otherwise it returns a buffer
Asynchronously writes data to a file, replacing the file if it already exists. data can be a string or a buffer
The synchronous version of fs.writeFile
Asynchronously append data to a file, creating the file if it not yet exists. data can be a string or a buffer
The synchronous version of fs.appendFile
Watch for changes on filename, where filename is either a file or a directory. The returned object is a fs.FSWatcher. The listener callback gets two arguments (event, filename). event is either 'rename' or 'change', and filename is the name of the file which triggered the event
Test whether or not the given path exists by checking with the file system. Then call the callback argument with either true or false. (should not be used)
Returns a new ReadStream object
Returns a new WriteStream object
Normalize a string path, taking care of '..' and '.' parts
Join all arguments together and normalize the resulting path
Resolves 'to' to an absolute path
Solve the relative path from 'from' to 'to'
Return the directory name of a path. Similar to the Unix dirname command
Return the extension of the path, from the last '.' to end of string in the last portion of the path
The platform-specific file separator. '\' or '/'
The platform-specific path delimiter, ';' or ':'
A collection of all the standard HTTP response status codes, and the short description of each
Set the method to GET and calls req.end() automatically
Returns a new web server object. The requestListener is a function which is automatically added to the 'request' event
Begin accepting connections on the specified port and hostname
Start a UNIX socket server listening for connections on the given path
The handle object can be set to either a server or socket (anything with an underlying _handle member), or a {fd: } object
Stops the server from accepting new connections
Sets the timeout value for sockets, and emits a 'timeout' event on the Server object, passing the socket as an argument, if a timeout occurs
Limits maximum incoming headers count, equal to 1000 by default. If set to 0 - no limit will be applied
The number of milliseconds of inactivity before a socket is presumed to have timed out
Emitted each time there is a request
When a new TCP stream is established
Emitted when the server closes
Emitted each time a request with an http Expect: 100-continue is received
Emitted each time a client requests a http CONNECT method
Emitted each time a client requests a http upgrade
If a client connection emits an 'error' event - it will forwarded here
Sends a chunk of the body
Finishes sending the request. If any parts of the body are unsent, it will flush them to the stream
Aborts a request
Once a socket is assigned to this request and is connected socket.setTimeout() will be called
Once a socket is assigned to this request and is connected socket.setNoDelay() will be called
Once a socket is assigned to this request and is connected socket.setKeepAlive() will be called
Emitted when a response is received to this request. This event is emitted only once
Emitted after a socket is assigned to this request
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
Emitted each time a server responds to a request with an upgrade. If this event isn't being listened for, clients receiving an upgrade header will have their connections closed
Emitted when the server sends a '100 Continue' HTTP response, usually because the request contained 'Expect: 100-continue'. This is an instruction that the client should send the request body
This sends a chunk of the response body. If this merthod is called and response.writeHead() has not been called, it will switch to implicit header mode and flush the implicit headers
Sends a HTTP/1.1 100 Continue message to the client, indicating that the request body should be sent
Sends a response header to the request
Sets the Socket's timeout value to msecs. If a callback is provided, then it is added as a listener on the 'timeout' event on the response object
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
Reads out a header that's already been queued but not sent to the client. Note that the name is case insensitive
Removes a header that's queued for implicit sending
This method adds HTTP trailing headers (a header but at the end of the message) to the response
This method signals to the server that all of the response headers and body have been sent; that server should consider this message complete. The method, response.end(), MUST be called on each response
When using implicit headers (not calling response.writeHead() explicitly), this property controls the status code that will be sent to the client when the headers get flushed
Boolean (read-only). True if headers were sent, false otherwise
When true, the Date header will be automatically generated and sent in the response if it is not already present in the headers. Defaults to true
Indicates that the underlying connection was terminated before response.end() was called or able to flush
Emitted when the response has been sent
In case of server request, the HTTP version sent by the client. In the case of client response, the HTTP version of the connected-to server
The request/response headers object
The request/response trailers object. Only populated after the 'end' event
The request method as a string. Read only. Example: 'GET', 'DELETE'
Request URL string. This contains only the URL that is present in the actual HTTP request
The net.Socket object associated with the connection
Calls message.connection.setTimeout(msecs, callback)
Take a URL string, and return an object
Take a parsed URL object, and return a formatted URL string
Take a base URL, and a href URL, and resolve them as a browser would for an anchor tag
This module provides utilities for dealing with query strings. Call require('querystring') to use it
Serialize an object to a query string. Optionally override the default separator ('&') and assignment ('=') characters
Deserialize a query string to an object. Optionally override the default separator ('&') and assignment ('=') characters
Throws an exception that displays the values for actual and expected separated by the provided operator
Tests if value is truthy, it is equivalent to assert.equal(true, !!value, message)
Tests shallow, coercive equality with the equal comparison operator ( == )
Tests shallow, coercive non-equality with the not equal comparison operator ( != )
Tests for deep equality
Tests for any deep inequality
Tests strict equality, as determined by the strict equality operator ( === )
Tests strict non-equality, as determined by the strict not equal operator ( !== )
Expects block to throw an error. error can be constructor, RegExp or validation function
Expects block not to throw an error, see assert.throws for details
Tests if value is not a false value, throws if it is a true value. Useful when testing the first argument, error in callbacks
Returns the operating system's default directory for temp files
Returns the endianness of the CPU. Possible values are "BE" or "LE"
Returns the hostname of the operating system
Returns the operating system name
Returns the operating system platform
Returns the operating system CPU architecture
Returns the operating system release
Returns the system uptime in seconds
Returns an array containing the 1, 5, and 15 minute load averages
Returns the total amount of system memory in bytes
Returns the amount of free system memory in bytes
Returns an array of objects containing information about each CPU/core installed: model, speed (in MHz), and times (an object containing the number of milliseconds the CPU/core spent in: user, nice, sys, idle, and irq)
Get a list of network interfaces
A constant defining the appropriate End-of-line marker for the operating system
Allocates a new buffer of size octets
Allocates a new buffer using an array of octets
Allocates a new buffer containing the given str. encoding defaults to 'utf8'
Returns true if the encoding is a valid encoding argument, or false otherwise
Tests if obj is a Buffer
Returns a buffer which is the result of concatenating all the buffers in the list together
Gives the actual byte length of a string
Writes string to the buffer at offset using the given encoding
Returns a JSON-representation of the Buffer instance, which is identical to the output for JSON Arrays
Does copy between buffers. The source and target regions can be overlapped
Returns a new buffer which references the same memory as the old, but offset and cropped by the start (defaults to 0) and end (defaults to buffer.length) indexes. Negative indexes start from the end of the buffer
Fills the buffer with the specified value
Get and set the octet at index
The size of the buffer in bytes, Note that this is not necessarily the size of the contents
How many bytes will be returned when buffer.inspect() is called. This can be overridden by user modules
ReactJS
notes: don't forget the command lines
Clone and return a new React element using element as the starting point
Verifies the object is a React element. Returns true or false
React.Children> provides utilities for dealing with the this.props.children opaque data structure
Like React.Children.map() but does not return an array
Returns the total number of components in children, equal to the number of times that a callback passed to map or forEach would be invoked
Verifies that children has only one child (a React element) and returns it
Returns the children opaque data structure as a flat array with keys assigned to each child
The React.Fragment component lets you return multiple elements in a render() method without creating an additional DOM element
The constructor is the right place to initialize state
In rare cases, it's okay to initialize state based on props
^^^^ Let React know if a component's output is not affected by the current change in state or props
shouldComponentUpdate() is invoked before rendering when new props or state are being received. Defaults to true
Contains data specific to this component that may change over time
By default, when your component's state or props change, your component will re-render
REACT.DOM
Same as render(), but is used to hydrate a container whose HTML contents were rendered
Remove a mounted React component from the DOM and clean up its event handlers and state
If this component has been mounted into the DOM, this returns the corresponding native browser
Creates a portal. Portals provide a way to render children into a DOM node that exists outside
REACTDOMSERVER
Similar to renderToString, except this doesn't create extra DOM attributes that React uses
Render a React element to its initial HTML. Returns a Readable stream that outputs an HTML string
Similar to renderToNodeStream, except this doesn't create extra DOM attributes that React uses
(or fragment) containing these types
optionalElement: PropTypes.element, You can also declare that a prop is an instance of a class. This uses
is shown if the prop isn't provided
You can also supply a custom validator to arrayOf and objectOf
arrayOf and objectOfLast updated