Node.js v4.0.0

Gábor `LaTotty` Tóth

Co-founder & Backend @ Coding Sans

History

Initial release

May 27, 2009

v0.0.1

io.js start

December 2014

io.js release

Jan 14, 2015

v1.0.0

Start of io.js merge

May 15, 2015

The big merge

Sept 8, 2015

v4.0.0

Sept 17, 2015

v4.1.0

Features

Promises


              function timeout(duration = 0) {
                return new Promise((resolve, reject) => {
                  setTimeout(resolve, duration);
                })
              }

              const p = timeout(1000).then(() => {
                return timeout(2000);
              }).then(() => {
                throw new Error('hmm');
              }).catch(err => {
                return Promise.all([timeout(100), timeout(200)]);
              })
            

Arrow


    const bob = {
      _name: 'Bob',
      _friends: [],
      printFriends() {
        this._friends.forEach(f =>
          console.log(this._name + ' knows ' + f));
      }
    };
            

Let & Const


              function f() {
                let x;
                {
                  // okay, block scoped name
                  const x = 'sneaky';
                  // error, const
                  x = 'foo';
                }
                // okay, declared with `let`
                x = 'bar';
                // error, already declared in block
                let x = 'inner';
              }
            

Generator


              function* idMaker(){
                let index = 0;
                while (index < 3) {
                  yield index++;
                }
              }

              const gen = idMaker();

              console.log(gen.next().value); // 0
              console.log(gen.next().value); // 1
              console.log(gen.next().value); // 2
              console.log(gen.next().value); // undefined
            

Classes


              class Cat {
                constructor(name) {
                  this.name = name;
                }
                speak() {
                  console.log(this.name + ' makes a noise.');
                }
              }
              class Lion extends Cat {
                speak() {
                  super.speak();
                  console.log(this.name + ' roars.');
                }
              }
            

Template strings


              const name = 'Bob', time = 'today';

              const str1 = `Hello ${name}, how are you ${time}?`

              const str2 = `I am
              multiline!`
            
  • Collections
    • Set
    • Map
    • WeakSet
    • WeakMap
  • Typed arrays
  • Symbols
  • ARM
  • Semantic Versioning

Async flow management

Callbacks


              asyncFn1(function(err, obj1) {
                if (err) {
                  //error handling
                  return;
                }
                asyncFn2(function(err, obj2) {
                  if (err) {
                    //error handling
                    return;
                  }
                  console.log('success');
                });
              });
            

Promises


              asyncFn1()
              .then(function() {
                return asyncFn2();
              })
              .then(function() {
                console.log('success');
              })
              .catch(function(err) {
                //error handling
              });
            

Coroutines


              co(function * asyncGeneratorFn() {
                try {
                  const obj1 = yield asyncFn1();

                  const obj2 = yield asyncFn2();
                } catch(err) {
                  //error handling
                }

                console.log('success');
              });
            

Async-await


              async function asyncFn() {
                try {
                  const obj1 = await asyncFn1();

                  const obj2 = await asyncFn2();
                } catch(err) {
                  //error handling
                }

                console.log('success');
              };
            

Production use

Thanks for your attention!

https://github.com/latotty

https://github.com/CodingSans

https://latotty.github.io/2015.mobilweekend/