\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{camilo.herbert} \pdfinfo{ /Title (node-cheatsheet.pdf) /Creator (Cheatography) /Author (camilo.herbert) /Subject (Node Cheatsheet Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{E6511A} \definecolor{LightBackground}{HTML}{FDF4F0} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{Node Cheatsheet Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{camilo.herbert} via \textcolor{DarkBackground}{\uline{cheatography.com/66323/cs/16551/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}camilo.herbert \\ \uline{cheatography.com/camilo-herbert} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 3rd August, 2018.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{3} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Basic Webserver example}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{var http = require('http'); \newline \newline http.createServer(function (request, response) \{ \newline response.writeHead(200, \{'Content-Type': 'text/plain'\}); \newline response.end('Hello World\textbackslash{}n'); \newline \}).listen(8124); \newline \newline console.log('Server running at \seqsplit{http://127.0.0.1:8124/');}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Timers}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{To schedule execution of a one-time callback after delay milliseconds. Optionally you can also pass arguments to the callback. \newline {\bf{setTimeout(callback, delay, {[}arg{]}, {[}...{]});}} \newline \newline Stop a timer that was previously created with setTimeout(). \newline {\bf{clearTimeout(t);}} \newline \newline To schedule the repeated execution of callback every delay milliseconds. Optionally you can also pass arguments to the callback. \newline {\bf{setInterval(callback, delay, {[}arg{]}, {[}...{]});}} \newline \newline Stop a timer that was previously created with setInterval(). \newline {\bf{clearInterval(t);}} \newline \newline To schedule the "immediate" execution of callback after I/O events callbacks and before setTimeout and setInterval. \newline {\bf{setImmediate(callback, {[}arg{]}, {[}...{]});}} \newline \newline Stop a timer that was previously created with setImmediate(). \newline {\bf{clearImmediate(immediateObject); }} \newline \newline 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. \newline {\bf{unref();}} \newline \newline If you had previously unref()d a timer you can call ref() to explicitly request the timer hold the program open. \newline {\bf{ref(); }}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Events}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Adds a listener to the end of the listeners array for the specified event. \newline {\bf{emitter.addListener(event, listener); }} \newline \newline Same as emitter.addListener(). \newline {\bf{emitter.on(event, listener);}} \newline \newline Adds a one time listener for the event. This listener is invoked only the next time the event is fired, after which it is removed. \newline {\bf{emitter.once(event, listener);}} \newline \newline Remove a listener from the listener array for the specified event. \newline {\bf{emitter.removeListener(event, listener);}} \newline \newline Removes all listeners, or those of the specified event. \newline {\bf{emitter.removeAllListeners({[}event{]});}} \newline \newline By default EventEmitters will print a warning if more than 10 listeners are added for a particular event. \newline {\bf{emitter.setMaxListeners(n);}} \newline \newline Returns an array of listeners for the specified event. \newline {\bf{emitter.listeners(event);}} \newline \newline Execute each of the listeners in order with the supplied arguments. Returns true if event had listeners, false otherwise. \newline {\bf{emitter.emit(event, {[}arg1{]}, {[}arg2{]}, {[}...{]});}} \newline \newline Return the number of listeners for a given event. \newline {\bf{EventEmitter.listenerCount(emitter, event);}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{File system}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Write buffer to the file specified by fd. \newline {\bf{fs.write(fd, buffer, offset, length, position, callback);}} \newline \newline Synchronous version of fs.write(). Returns the number of bytes written. \newline {\bf{fs.writeSync(fd, buffer, offset, length, position);}} \newline \newline Read data from the file specified by fd. \newline {\bf{fs.read(fd, buffer, offset, length, position, callback);}} \newline \newline Synchronous version of fs.read. Returns the number of bytesRead. \newline {\bf{fs.readSync(fd, buffer, offset, length, position);}} \newline \newline Asynchronously reads the entire contents of a file. \newline {\bf{fs.readFile(filename, {[}options{]}, callback);}} \newline \newline 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. \newline {\bf{fs.readFileSync(filename, {[}options{]});}} \newline \newline Asynchronously writes data to a file, replacing the file if it already exists. data can be a string or a buffer. \newline {\bf{fs.writeFile(filename, data, {[}options{]}, callback);}} \newline \newline The synchronous version of fs.writeFile. \newline {\bf{fs.writeFileSync(filename, data, {[}options{]});}} \newline \newline Asynchronously append data to a file, creating the file if it not yet exists. data can be a string or a buffer. \newline {\bf{fs.appendFile(filename, data, {[}options{]}, callback);}} \newline \newline The synchronous version of fs.appendFile. \newline {\bf{fs.appendFileSync(filename, data, {[}options{]});}} \newline \newline 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. \newline {\bf{fs.watch(filename, {[}options{]}, {[}listener{]});}} \newline \newline 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) \newline {\bf{fs.exists(path, callback);}} \newline \newline Synchronous version of fs.exists. (should not be used) \newline {\bf{fs.existsSync(path);}} \newline \newline fs.Stats: objects returned from fs.stat(), fs.lstat() and fs.fstat() and their synchronous counterparts are of this type. \newline {\bf{stats.isFile();}} \newline {\bf{stats.isDirectory()}} \newline {\bf{stats.isBlockDevice()}} \newline {\bf{stats.isCharacterDevice()}} \newline {\bf{stats.isSymbolicLink()}} // (only valid with fs.lstat()) \newline {\bf{stats.isFIFO()}} \newline {\bf{stats.isSocket()}} \newline \newline Returns a new ReadStream object. \newline {\bf{fs.createReadStream(path, {[}options{]});}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{HTTP - Requests}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Sends a chunk of the body. \newline {\bf{request.write(chunk, {[}encoding{]});}} \newline \newline Finishes sending the request. If any parts of the body are unsent, it will flush them to the stream. \newline {\bf{request.end({[}data{]}, {[}encoding{]});}} \newline \newline Aborts a request. \newline {\bf{request.abort();}} \newline \newline Once a socket is assigned to this request and is connected socket.setTimeout() will be called. \newline {\bf{request.setTimeout(timeout, {[}callback{]});}} \newline \newline Once a socket is assigned to this request and is connected socket.setNoDelay() will be called. \newline {\bf{request.setNoDelay({[}noDelay{]});}} \newline \newline Once a socket is assigned to this request and is connected socket.setKeepAlive() will be called. \newline {\bf{request.setSocketKeepAlive({[}enable{]}, {[}initialDelay{]});}} \newline \newline Emitted when a response is received to this request. This event is emitted only once. \newline {\bf{request.on('response', function(response) \{ \});}} \newline \newline Emitted after a socket is assigned to this request. \newline {\bf{request.on('socket', function(socket) \{ \});}} \newline \newline 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. \newline {\bf{request.on('connect', function(response, socket, head) \{ \});}} \newline \newline 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. \newline {\bf{request.on('upgrade', function(response, socket, head) \{ \});}} \newline \newline 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. \newline {\bf{request.on('continue', function() \{ \});}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Global Objects}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{The filename of the code being executed. (absolute path) \newline {\bf{\_\_filename; }} \newline \newline The name of the directory that the currently executing script resides in. (absolute path) \newline {\bf{\_\_dirname;}} \newline \newline A reference to the current module. In particular module.exports is used for defining what a module exports and makes available through require(). \newline {\bf{module;}} \newline \newline A reference to the module.exports that is shorter to type. \newline {\bf{exports;}} \newline \newline The process object is a global object and can be accessed from anywhere. It is an instance of EventEmitter. \newline {\bf{process;}} \newline \newline The Buffer class is a global type for dealing with binary data directly. \newline {\bf{Buffer;}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Modules}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Loads the module module.js in the same directory. \newline {\bf{var module = require('./module.js');}} \newline \newline load another\_module as if require() was called from the module itself. \newline {\bf{module.require('./another\_module.js');}} \newline \newline The identifier for the module. Typically this is the fully resolved filename. \newline {\bf{module.id;}} \newline \newline The fully resolved filename to the module. \newline {\bf{module.filename;}} \newline \newline Whether or not the module is done loading, or is in the process of loading. \newline {\bf{module.loaded;}} \newline \newline The module that required this one. \newline {\bf{module.parent;}} \newline \newline The module objects required by this one. \newline {\bf{module.children;}} \newline \newline \newline exports.area = function (r) \{ \newline return Math.PI {\emph{ r }} r; \newline \}; \newline \newline If you want the root of your module's export to be a function (such as a constructor) \newline or if you want to export a complete object in one assignment instead of building it one property at a time, \newline assign it to module.exports instead of exports. \newline \newline module.exports = function(width) \{ \newline return \{ \newline area: function() \{ \newline return width * width; \newline \} \newline \}; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Stream - Writable}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{var writer = getWritableStreamSomehow();}} \newline \newline This method writes some data to the underlying system, and calls the supplied callback once the data has been fully handled. \newline {\bf{writable.write(chunk, {[}encoding{]}, {[}callback{]});}} \newline \newline 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. \newline {\bf{writer.once('drain', write);}} \newline \newline Call this method when no more data will be written to the stream. \newline {\bf{writable.end({[}chunk{]}, {[}encoding{]}, {[}callback{]});}} \newline \newline When the end() method has been called, and all data has been flushed to the underlying system, this event is emitted. \newline {\bf{writer.on('finish', function() \{\});}} \newline \newline This is emitted whenever the pipe() method is called on a readable stream, adding this writable to its set of destinations. \newline {\bf{writer.on('pipe', function(src) \{\});}} \newline \newline This is emitted whenever the unpipe() method is called on a readable stream, removing this writable from its set of destinations. \newline {\bf{writer.on('unpipe', function(src) \{\});}} \newline \newline Emitted if there was an error when writing or piping data. \newline {\bf{writer.on('error', function(src) \{\});}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Path}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Normalize a string path, taking care of '..' and '.' parts. \newline {\bf{path.normalize(p);}} \newline \newline Join all arguments together and normalize the resulting path. \newline {\bf{path.join({[}path1{]}, {[}path2{]}, {[}...{]});}} \newline \newline Resolves 'to' to an absolute path. \newline {\bf{path.resolve({[}from ...{]}, to);}} \newline \newline Solve the relative path from 'from' to 'to'. \newline {\bf{path.relative(from, to);}} \newline \newline Return the directory name of a path. Similar to the Unix dirname command. \newline {\bf{path.dirname(p);}} \newline \newline Return the last portion of a path. Similar to the Unix basename command. \newline {\bf{path.basename(p, {[}ext{]});}} \newline \newline Return the extension of the path, from the last '.' to end of string in the last portion of the path. \newline {\bf{path.extname(p);}} \newline \newline The platform-specific file separator. '\textbackslash{}\textbackslash{}' or '/'. \newline {\bf{path.sep;}} \newline \newline The platform-specific path delimiter, ';' or ':'. \newline {\bf{path.delimiter;}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{HTTP - Server Events}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Emitted each time there is a request. \newline {\bf{server.on('request', function (request, response) \{ \});}} \newline \newline When a new TCP stream is established. \newline {\bf{server.on('connection', function (socket) \{ \});}} \newline \newline Emitted when the server closes. \newline {\bf{server.on('close', function () \{ \});}} \newline \newline Emitted each time a request with an http Expect: 100-continue is received. \newline {\bf{server.on('checkContinue', function (request, response) \{ \});}} \newline \newline Emitted each time a client requests a http CONNECT method. \newline {\bf{server.on('connect', function (request, socket, head) \{ \});}} \newline \newline Emitted each time a client requests a http upgrade. \newline {\bf{server.on('upgrade', function (request, socket, head) \{ \});}} \newline \newline If a client connection emits an 'error' event - it will forwarded here. \newline {\bf{server.on('clientError', function (exception, socket) \{ \});}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{HTTP - Responses}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{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. \newline {\bf{response.write(chunk, {[}encoding{]});}} \newline \newline Sends a HTTP/1.1 100 Continue message to the client, indicating that the request body should be sent. \newline {\bf{response.writeContinue();}} \newline \newline Sends a response header to the request. \newline {\bf{response.writeHead(statusCode, {[}reasonPhrase{]}, {[}headers{]});}} \newline \newline 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. \newline {\bf{response.setTimeout(msecs, callback);}} \newline \newline 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. \newline {\bf{response.setHeader(name, value);}} \newline \newline Reads out a header that's already been queued but not sent to the client. Note that the name is case insensitive. \newline {\bf{response.getHeader(name);}} \newline \newline Removes a header that's queued for implicit sending. \newline {\bf{response.removeHeader(name);}} \newline \newline This method adds HTTP trailing headers (a header but at the end of the message) to the response. \newline {\bf{response.addTrailers(headers);}} \newline \newline 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. \newline {\bf{response.end({[}data{]}, {[}encoding{]});}} \newline \newline When using implicit headers (not calling response.writeHead() explicitly), this property controls the status code that will be sent to the client when \newline the headers get flushed. \newline {\bf{response.statusCode;}} \newline \newline Boolean (read-only). True if headers were sent, false otherwise. \newline {\bf{response.headersSent;}} \newline \newline 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. \newline {\bf{response.sendDate;}} \newline \newline Indicates that the underlying connection was terminated before response.end() was called or able to flush. \newline {\bf{response.on('close', function () \{ \});}} \newline \newline Emitted when the response has been sent. \newline {\bf{response.on('finish', function() \{ \});}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Console}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Prints to stdout with newline. \newline {\bf{console.log({[}data{]}, {[}...{]});}} \newline \newline Same as console.log. \newline {\bf{console.info({[}data{]}, {[}...{]}); }} \newline \newline Same as console.log but prints to stderr. \newline {\bf{console.error({[}data{]}, {[}...{]}); }} \newline \newline Same as console.error. \newline {\bf{console.warn({[}data{]}, {[}...{]});}} \newline \newline Uses util.inspect on obj and prints resulting string to stdout. \newline {\bf{console.dir(obj); }} \newline \newline Mark a time. \newline {\bf{console.time(label);}} \newline \newline Finish timer, record output. \newline {\bf{console.timeEnd(label);}} \newline \newline Print a stack trace to stderr of the current position. \newline {\bf{console.trace(label); }} \newline \newline Same as assert.ok() where if the expression evaluates as false throw an AssertionError with message. \newline {\bf{console.assert(expression, {[}message{]}); }}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Process}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Emitted when the process is about to exit \newline {\bf{process.on('exit', function(code) \{\});}} \newline \newline Emitted when an exception bubbles all the way back to the event loop. (should not be used) \newline {\bf{process.on('uncaughtException', function(err) \{\});}} \newline \newline A writable stream to stdout. \newline {\bf{process.stdout;}} \newline \newline A writable stream to stderr. \newline {\bf{process.stderr;}} \newline \newline A readable stream for stdin. \newline {\bf{process.stdin; }} \newline \newline An array containing the command line arguments. \newline {\bf{process.argv; }} \newline \newline An object containing the user environment. \newline {\bf{process.env; }} \newline \newline This is the absolute pathname of the executable that started the process. \newline {\bf{process.execPath;}} \newline \newline This is the set of node-specific command line options from the executable that started the process. \newline {\bf{process.execArgv;}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Stream - Readable}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{var readable = getReadableStreamSomehow();}} \newline \newline When a chunk of data can be read from the stream, it will emit a 'readable' event. \newline {\bf{readable.on('readable', function() \{\});}} \newline \newline 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. \newline {\bf{readable.on('data', function(chunk) \{\});}} \newline \newline This event fires when there will be no more data to read. \newline {\bf{readable.on('end', function() \{\});}} \newline \newline Emitted when the underlying resource (for example, the backing file descriptor) has been closed. Not all streams will emit this. \newline {\bf{readable.on('close', function() \{\});}} \newline \newline Emitted if there was an error receiving data. \newline {\bf{readable.on('error', function() \{\});}} \newline \newline The read() method pulls some data out of the internal buffer and returns it. If there is no data available, then it will return null. \newline This method should only be called in non-flowing mode. In flowing-mode, this method is called automatically until the internal buffer is drained. \newline {\bf{readable.read({[}size{]});}} \newline \newline Call this function to cause the stream to return strings of the specified encoding instead of Buffer objects. \newline {\bf{readable.setEncoding(encoding);}} \newline \newline This method will cause the readable stream to resume emitting data events. \newline {\bf{readable.resume();}} \newline \newline This method will cause a stream in flowing-mode to stop emitting data events. \newline {\bf{readable.pause();}} \newline \newline 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. \newline {\bf{readable.pipe(destination, {[}options{]});}} \newline \newline This method will remove the hooks set up for a previous pipe() call. If the destination is not specified, then all pipes are removed. \newline {\bf{readable.unpipe({[}destination{]});}} \newline \newline 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. \newline {\bf{readable.unshift(chunk);}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{HTTP}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{A collection of all the standard HTTP response status codes, and the short description of each. \newline {\bf{http.STATUS\_CODES;}} \newline \newline This function allows one to transparently issue requests. \newline {\bf{http.request(options, {[}callback{]});}} \newline \newline Set the method to GET and calls req.end() automatically. \newline {\bf{http.get(options, {[}callback{]});}} \newline \newline Returns a new web server object. The requestListener is a function which is automatically added to the 'request' event. \newline {\bf{server = http.createServer({[}requestListener{]});}} \newline \newline Begin accepting connections on the specified port and hostname. \newline {\bf{server.listen(port, {[}hostname{]}, {[}backlog{]}, {[}callback{]});}} \newline \newline Start a UNIX socket server listening for connections on the given path. \newline {\bf{server.listen(path, {[}callback{]});}} \newline \newline The handle object can be set to either a server or socket (anything with an underlying \_handle member), or a \{fd: \textless{}n\textgreater{}\} object. \newline {\bf{server.listen(handle, {[}callback{]});}} \newline \newline Stops the server from accepting new connections. \newline {\bf{server.close({[}callback{]});}} \newline \newline 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. \newline {\bf{server.setTimeout(msecs, callback);}} \newline \newline Limits maximum incoming headers count, equal to 1000 by default. If set to 0 - no limit will be applied. \newline {\bf{server.maxHeadersCount;}} \newline \newline The number of milliseconds of inactivity before a socket is presumed to have timed out. \newline {\bf{server.timeout;}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{HTTP - Messages}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{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. \newline {\bf{message.httpVersion;}} \newline \newline The request/response headers object. \newline {\bf{message.headers;}} \newline \newline The request/response trailers object. Only populated after the 'end' event. \newline {\bf{message.trailers;}} \newline \newline The request method as a string. Read only. Example: 'GET', 'DELETE'. \newline {\bf{message.method;}} \newline \newline Request URL string. This contains only the URL that is present in the actual HTTP request. \newline {\bf{message.url;}} \newline \newline The 3-digit HTTP response status code. E.G. 404. \newline {\bf{message.statusCode;}} \newline \newline The net.Socket object associated with the connection. \newline {\bf{message.socket;}} \newline \newline Calls \seqsplit{message.connection.setTimeout(msecs}, callback). \newline {\bf{message.setTimeout(msecs, callback);}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}