Jim Cheung

Node.js

IDE:

REPL

Core

Global Objects

global
global is global namespace object, similar to windows in a browser environment. To print out global object, under REPL:

console.log(global);

process

    process.stdin.resume();
    process.stdin.on('data', function(chunk){
        process.stdout.write(chunk);
    });
    setTimeout(function() {
        callback(val);
    }, 0);
    // more efficient
    function asynchFunction = function (data, callback) {
        process.nextTick(function() {
            callback(val);
        });
     );

buffer
buffer handles binary data in Node.

    buf.write(string); // offset defaults to 0, length defaults to buffer.length - offset, encoding is utf8

TCP Sockets and Servers

A socket is an endpoint in a communication. The data flows between the sockets in what’s known as a stream. The data in the stream can be transmitted as binary data in a buffer, or in Unicode as a string.