Node v0.12

Upcoming meetings

  • IO.JS
  • ES6
  • Babel transpiler

Would you like
to Speak?

Anything Javascript

APIs and IPAs

Tomorrow (think NUSH)

0.12

  • Backwards compatible
  • Improvements to internals
  • Streams 3
  • V8 version 3.28.73, 0.10 used 3.14.5.9
  • IO.JS uses 4.1.0.21

Node 0.12 features

Streams 3

Corking and Uncorking

Http maxSockets defaults to unlimited

Cluster has two modes;

Default is round robin, can still let workers accept connections

Buffer memory improvements

TLS improvements

TLS asynchronous SNI callbacks

TLS OCSP stapling

TLS storage events

spawnSync/execSync commands

New Crypto APIs

VM improvements

ECMA-402 support

Streams 3

  • Still works the same way as 0.10
  • .pipe()
  • lazily produce or handle chunks
  • Allow you to work around V8 memory limits
  • Evented and non-blocking
  • https://github.com/substack/stream-handbook

5 Classes of Streams

  • Readable
  • Writable
  • Duplex
  • Transform, inflight changes
  • Passthrough

HTTP Changes

  • maxSockets now Infinity
  • 0.10 is limited to 5
  • proper keep Alive support
  • Sockets will stay open until timeout,
    closed by remote, or process exits
  • Can explicitly call flushHeaders()

Cluster changes

  • New Round Robin approach
  • Master determines which worker instead of the OS
  • Can still use the old method
  • Use NODE_CLUSTER_SCHED_POLICY
      either "none" or "rr"
var cluster = require('cluster');
// Set this before calling other cluster functions.
cluster.schedulingPolicy = cluster.SCHED_NONE;
cluster.fork();

Buffer changes

  • Better GC, quicker
  • Lower memory footprint
  • Uses CPU less

Synchronous Child Processes

  • Why?
  • Running shell commands asynchronously is bad! 
  • spawnSync/execSync
  • Warning, these are blocking calls

Calling shell

var exec = require('child_process').execFileSync
var $ = require('cheerio')
 
var html = exec('curl', ['-s', 'http://nodejs.org/']).toString()
var version = $(html).find('.version')
                     .text()
                     .replace(/^.*\s(?=v)/,'')
console.log(version)

Spawn Sync

var spawn = require('child_process').spawnSync
var $ = require('cheerio')

var child = spawn('curl', ['-s', 'http://nodejs.org/'])
console.log('curl exited with status %d', child.status)
var html = child.stdout.toString()
var version = $(html).find('.version')
                     .text()
                     .replace(/^.*\s(?=v)/,'')
console.log(version)

TLS and Crypto

  • TLSWrap cuts down on network hops
  • Added new Crypto APIs
  • More APIs support pass phrases
  • New APIs for RSA puplic/private keys for encryption/decryption

ES6

  • Officially supports ECMA-402
  • English only
  • --use-strict
  • Still need --harmony for class and =>

Testing different Nodes

  • node --version
  • use NVM to test with different version of Node
  • NVM also works with IO.JS
  • nvm use 0.10
  • nvm install 0.12

Demo

Questions?

Resources

  • https://nodejs.org
  • https://strongloop.com/node-js/whats-new-in-node-js-v0-12/
  • https://github.com/substack/stream-handbook

Contact Me

  • Twitter @jaxnode
  • @davidfekke
  • Skype me davidfekke
  • email David Fekke at gmail dot com