Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to Node.JS 8

Introduction to Node.JS 8

☁ Rheza Satria

July 25, 2017
Tweet

Other Decks in Programming

Transcript

  1. ES 8 ES 7 (ES 2016) ES 6 (ES 2015)

    ES 5 ES 3 Core features 1997 ~~ 1999 new functions strict mode, json 2009 class, promises, generators, arrow functions, new syntax and concepts … 2015 Exponential (**), array.includes, 2016
  2. is a specific term for taking source code written in

    one language and transforming into another language that has a similar level of abstraction is the general term for taking source code written in one language and transforming into another. "CoffeeScript is to Ruby as TypeScript is to Java/C#/C++." - Luke Hoban
  3. - Latest LTS is 6.11.2, and 8.2.1 will be new

    LTS candidate this year - We call it Node 8 instead of Node v8, because it will lead confusion with javascript engine v8
  4. Seems easy to execute just passing function as param, but

    this leads to know problem: Callback hell
  5. Good: - Using chainable promise - Clear flow Bad: -

    Might become difficult when managing complex logic to pass around the data
  6. Good: - Understandable API Bad: - Might become difficult when

    managing complex logic to pass around the data - Need 3rd party “async” library (uh-oh)
  7. Good: - Using generator function - Good way to control

    data flow Bad: - Need 3rd party “co” library (uh-oh)
  8. Good: - Using native syntax and implementation - Good way

    to control data flow Bad: - Need transpiler if want to support NodeJS version 8 / 7.10 and below
  9. Node 8 / NPM 5 § --save by default §

    Autmaticaly create a package-lock.json § npm cache rewrited § You will have to re-download all your package cache § npm fallback automaticaly to cache if no network § -- prefer-offline § -- prefer-online § -- offline § Large package download issue resolved
  10. § Platform for building native addons. § Independant from the

    underlying JavaScript Runtime § API is Application Binary Interface (ABI) stable accross Node.JS § Every native addons will be compatible with § Chrome V8 § ChakraCore (https://github.com/nodejs/node-chakracore/ )
  11. async_hooks : nodejs async tracing “tracking the lifetime of asynchronous

    resources created inside a Node.js application” const async_hooks = require('async_hooks'); const cid = async_hooks.currentId(); const tid = async_hooks.triggerId(); const asyncHook = async_hooks.createHook({ init, before, after, destroy }); asyncHook.enable(); function init(asyncId, type, triggerId, resource) {} function before(asyncId) {} function after(asyncId) {} function destroy(asyncId) {}
  12. § URL Standard : https://url.spec.whatwg.org/ § The URL Standard defines

    URLs, domains, IP addresses, the application/x-www-form- urlencoded format, and their API. § The URL standard takes the following approach towards making URLs fully interoperable import * as urlUtility from 'url'; const myUrl = new urlUtility.URL('/a/path', 'https://example.org/'); console.log(myUrl.toString());
  13. function breeze(a: number, callback: (err: any, value?: number) => void)

    { if (a > 10) { callback(undefined, a * a); } else { callback("a must be greater than 10"); } } const awaitableBreeze = util.promisify(bullshot); § util.promisify() API that allows standard Node.js callback style APIs to be wrapped in a function that returns a Promise § Callback Style : (err, value) => {}
  14. - Calling `Buffer(num)` will return zero-filled `Buffer` instance. - Prior

    Node.JS would return uninitialized memory, which could contain sensitive data - Use `--pending-deprecation` to trigger deprecation warning
  15. - Now, every `stream` instance will now inherit a `destroy()`

    method. - Implementation, can be by inheriting `_destroy` method - Add `_final` method for writable stream
  16. TLS: `rejectUnauthorized` option now defaults to `true` Util: `Symbol` keys

    are now displayed by default when using util.inspect() Util: `toJSON` errors will be thrown when formatting `%j` Others… See 1. https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V8.md 2. https://nodejs.org/en/blog/release/v8.0.0/