SlideShare a Scribd company logo
NodeJS future
NodeJS 8.9
NodeJS 9.2
NodeJS VNext
ES6
ES7
ES8
And Michael Jackson…
@sebastienpertus (from Microsoft  )
ES6 / ES7 / ES2015 / ES2016
" ES7 is ES2016"
" ES6 is ES2015 "
" Too long for twitter … "
" How many people here are going to say ES2016 "
" Nobody, good ! "
Ecmascript from past to future
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
Where we are today
ES6 : Where we are today
• > 94%
• > 96% in nighty builds
http://kangax.github.io/compat-table/es6/
ES7 : Where we are today
Chakra
SpiderMonkey
V8
JavaScript Core
Nighty builds
TypeScript 2.6
Transpiler vs Compiler
Transpiler
is a specific term for taking source
code written in one language and
transforming into another
language that has a similar level of
abstraction
Compiler
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
Future of NodeJS
Future of NodeJS
Future of NodeJS
Future of NodeJS
Future of NodeJS
The feature gap
Future of NodeJS
And what about Node ?
Node version
Node.js 9.2.0 14/11/2017
Node.js 8.9.1 07/11/2017
Node.js 7.10.1 11/07/2017
Node.js 6.11.4 03/10/2017
ES support : http://node.green/
• > 98% from node 7.5 +
Enhancement Proposals : node-eps
• https://github.com/nodejs/node-eps
• Stream
• ES modules
• Url
• Asynchronous API
NodeJS CTC
• Node.js Core Technical Committee & Collaborators
• https://github.com/nodejs/CTC
From Node 7.5 (with love)
Not the future anymore… but maybe we should talk about …
ES5 : Async Programming
/* Callback Hell */
myFirstOperation(function(err, firstResult){
mySecondOperation(firstResult, function(err, secondResult){
myThirdOperation(secondResult, function(err, thirdResult){
/*
HELL !!!
*/
});
});
});
ES6 : Async Programming
/* Promises */
var myFirstPromise = new Promise(function (resolve, reject) {
// Do something
var everyhtingIsOk = true;
var result = { a: 12, b: "ok" };
if (everyhtingIsOk) {
resolve(result);
} else {
reject(Error('Something went wrong'));
}
});
ES6 : Async Programming
/* Promises */
myFirstPromise()
.then(firstResult => mySecondPromise(firstResult))
.then(secondResult => myThirdPromise(secondResult))
.then(thirdResult => {
/*
Code utilisant le 3ème résultat
*/
}).catch(err => {
/*
Gestion de l’erreur, quelque soit l’étape où elle a eu lieu
*/
});
ES7 : Async Programming
/* async await */
async function myOperations(){
const firstResult = await myFirstOperation();
const secondResult = await mySecondOperation(firstResult);
const thirdResult = await myThirdOperation(secondResult);
/*
Code
*/
};
try {
myOperations();
} catch (err) {
/*
Gestion de l’erreur, quelque soit l’étape où elle a eu lieu
*/
}
async / await
Future of NodeJS
Node 8 / NPM 5
NPM 5.0.0
• --save by default
• Autmaticaly create a package-
lock.json
• npm cache rewrited
• You will have to ree-download all
your package cache
• npm fallback automaticaly to cache
if no network
• -- prefer-offline
• -- prefer-online
• -- offline
• Large package download issue
resolved
http://www.standardista.com/six-
best-new-features-in-npm-5/
Future of NodeJS
Nouveautés Node 8
• Say hello to V8 5.8
• Forward compatibility with V8 5.9 and V8 6.0
Node.js API (N-API)
• 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/ )
Future of NodeJS
Node 8 : async_hooks
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) {}
Node 8 : WHATWG URL Standard
• 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());
Node 8 : util.promisify()
• 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) => {}
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(breeze);
NodeJS Future (9, 10)
Future of NodeJS
Les Modules
CommonJS / AMD / ESM ?
Modules in Browser
• Safari 10.1
• Chrome canary 60
• Firefox 54
• Edge 15
With FLAGS
https://jakearchibald.com/2017/es-modules-in-browsers/
NodeJS modules : CommonJS
• Synchronous
• Evaluated during runtime
ESM vs CJS
export class person {
getFullName() { return `${this.lastName} ${this.firstName}`; }
}
import * as people from './person';
var p = new people.person();
class person {
getFullName() { return `${this.lastName} ${this.firstName}`; }
}
exports.person = person;
const people = require("./person");
var p = new people.person();
ESM modules in NodeJS
• https://github.com/nodejs/node-eps/blob/master/002-es-
modules.md
• Implement interoperability for EcmaScript 6 modules (ESM) and
Node’s existing module system (CJS)
• Allow a common module syntax for Browser (ES6 spec) and Server
side
EF modules vs NodeJS modules
• CommonJS is a dynamic loader modules system
• Synchronous
• Evaluated during runtime
• ES is a static loader modules system
• Asynchronous
• Evaluated during parse time
Example
console.log('entry eval');
require('middle');
console.log('entry done);
export {};
console.log('middle eval');
require('right');
console.log('middle done');
entry eval
middle eval
right eval
right done
middle done
entry done
export {};
console.log('right eval');
console.log('right done');
entry eval
entry done
middle eval
middle done
right eval
right done
sync async
What Node wants to :
Node wants to be able to :
• Import a CJS module from ES (import from 'commonjs-module’ )
• Import a ESM module from CJS (require('es6-module’))
ESM vs CJS. Solutions evaluated ?
• Does Node.js want to ship a synchronous or asynchronous module
loader?
• Returning a promise (async)
• Returning an object (sync)
• Both ?
• Multiple Solutions investigated:
• Use CJS (require) for actuals .js files / Use ESM (import) with a newly file .mjs
• Use a double parsing time
• Config file
• Obiwan Kenobi
Future of NodeJS
Detectiong CJS / ES Modules
• https://github.com/nodejs/node/wiki/ES6-Module-Detection-in-Node
• https://github.com/dherman/defense-of-dot-js/blob/master/proposal.md
References
• http://codeheroics.github.io/talks/nodemjs/
• https://medium.com/the-node-js-collection/an-update-on-es6-modules-in-
node-js-42c958b890c
• https://hackernoon.com/node-js-tc-39-and-modules-a1118aecf95e
• https://medium.com/webpack/the-state-of-javascript-modules-
4636d1774358
• https://github.com/nodejs/node-eps/blob/master/002-es6-modules.md
• https://github.com/nodejs/node-eps/issues/57 (mjs tradeoff)
• http://2ality.com/2017/01/babel-esm-spec-mode.html
• http://2ality.com/2017/05/es-module-specifiers.html
Michael Jackson Script
• Code compiler must know if it’s a CJS or ES module
• In certain circumstance an import * from ‘foo’ could be a
CJS module or an ES module (same syntax !)
• Node.js will need to have some kind of mechanism for
identifying in advance what kind of file is being loaded
• foo.js will treat foo.js as CommonJS
• bar.mjs will treat bar.mjs as an ESM Module.
console.log(`Module load ${Date()}`)
Or ..
Changing ES Modules spec in ECMASCRIPT :
• A module allways requires an import or an export
• All modules are parsed. If it doesn't contain any of these statements,
it is not an ES Module.
Or …
Would be recognized as a CommonJS module, while
Would be an ES module.
console.log(`Module load ${Date()}`)
console.log(`Module load ${Date()}`)
export{}
But…
•It works within Babel / Typescript !!
•Under the hood, it’s just a
transpilation to CJS Modules 
Timeline
• At the current point in time, there are still a number of specification
and implementation issues that need to happen on the ES6 and
Virtual Machine side of things before Node.js can even begin working
up a supportable implementation of ES6 modules. Work is in progress
but it is going to take some time —
We’re currently looking at around a year at least.
• Node V10 « around October 2018 »
https://github.com/nodejs/Release
ES6 : Modules (ESM)
• TypeScript : Transpiling ESM Syntax in CommonJS modules
• Node.js 9+ : Implementation with flags
import {Person} from "./People";
import {Person, Material as M} from "./People";
import * as People from "./People";
import guy from './People';
Future of NodeJS
https://medium.com/web-on-the-edge/es-modules-in-node-today-32cff914e4b
ES Modules in Node Today
with polyfil @std/esm
@std/esm
Works from Node.js 4
Use *.mjs modules file extension
Questions ?
@sebastienpertus

More Related Content

PDF
(C)NodeJS
PDF
Fundamental of Node.JS - Internship Presentation - Week7
PPTX
Node js introduction
PDF
Nodejs presentation
PDF
Introduction to Node.js
PPTX
NodeJS
PDF
Philly Tech Week Introduction to NodeJS
PPTX
Introduction Node.js
(C)NodeJS
Fundamental of Node.JS - Internship Presentation - Week7
Node js introduction
Nodejs presentation
Introduction to Node.js
NodeJS
Philly Tech Week Introduction to NodeJS
Introduction Node.js

What's hot (20)

PPTX
Introduction to Node js
PPTX
Java script at backend nodejs
PPTX
Node.js tutoria for beginner
PDF
PDF
PDF
Use Node.js to create a REST API
PDF
Non-blocking I/O, Event loops and node.js
PDF
Getting started with developing Nodejs
PDF
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
PDF
All aboard the NodeJS Express
PDF
Complete MVC on NodeJS
PPT
Nodejs Event Driven Concurrency for Web Applications
PDF
JavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
PDF
Server Side Event Driven Programming
KEY
OSCON 2011 - Node.js Tutorial
PPTX
Introduction to Node.js
PDF
Node.js and How JavaScript is Changing Server Programming
PPTX
Node.js Patterns for Discerning Developers
PPTX
Nodejs intro
PPTX
Intro to Node.js (v1)
Introduction to Node js
Java script at backend nodejs
Node.js tutoria for beginner
Use Node.js to create a REST API
Non-blocking I/O, Event loops and node.js
Getting started with developing Nodejs
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
All aboard the NodeJS Express
Complete MVC on NodeJS
Nodejs Event Driven Concurrency for Web Applications
JavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
Server Side Event Driven Programming
OSCON 2011 - Node.js Tutorial
Introduction to Node.js
Node.js and How JavaScript is Changing Server Programming
Node.js Patterns for Discerning Developers
Nodejs intro
Intro to Node.js (v1)
Ad

Similar to Future of NodeJS (20)

PDF
(2018) Webpack Encore - Asset Management for the rest of us
PDF
New and upcoming features in the Node.js module loaders
PDF
Webpack Encore - Asset Management for the rest of us
PPTX
EcamScript (ESM) It's about time !
PPTX
Intro To Node.js
PDF
Helma / RingoJS – Vienna.js Minitalk
PDF
OUTDATED (Encore)
PPT
RESTful API In Node Js using Express
PDF
soft-shake.ch - Hands on Node.js
PDF
Node intro
PDF
Web (dis)assembly
PPTX
introduction to node.js
PPT
JS everywhere 2011
PDF
Jaap : node, npm & grunt
PDF
Introduction to REST API with Node.js
PDF
Node.js - async for the rest of us.
PPTX
ES6 - JavaCro 2016
PPTX
Discovering OpenBSD on AWS
PPTX
Building and Scaling Node.js Applications
PDF
Nodejs a-practical-introduction-oredev
(2018) Webpack Encore - Asset Management for the rest of us
New and upcoming features in the Node.js module loaders
Webpack Encore - Asset Management for the rest of us
EcamScript (ESM) It's about time !
Intro To Node.js
Helma / RingoJS – Vienna.js Minitalk
OUTDATED (Encore)
RESTful API In Node Js using Express
soft-shake.ch - Hands on Node.js
Node intro
Web (dis)assembly
introduction to node.js
JS everywhere 2011
Jaap : node, npm & grunt
Introduction to REST API with Node.js
Node.js - async for the rest of us.
ES6 - JavaCro 2016
Discovering OpenBSD on AWS
Building and Scaling Node.js Applications
Nodejs a-practical-introduction-oredev
Ad

Recently uploaded (20)

PDF
KodekX | Application Modernization Development
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Electronic commerce courselecture one. Pdf
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
cuic standard and advanced reporting.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Spectroscopy.pptx food analysis technology
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Empathic Computing: Creating Shared Understanding
PPT
Teaching material agriculture food technology
PPTX
MYSQL Presentation for SQL database connectivity
KodekX | Application Modernization Development
Encapsulation_ Review paper, used for researhc scholars
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
NewMind AI Weekly Chronicles - August'25 Week I
Electronic commerce courselecture one. Pdf
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
cuic standard and advanced reporting.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Big Data Technologies - Introduction.pptx
Spectroscopy.pptx food analysis technology
Chapter 3 Spatial Domain Image Processing.pdf
Empathic Computing: Creating Shared Understanding
Teaching material agriculture food technology
MYSQL Presentation for SQL database connectivity

Future of NodeJS

  • 1. NodeJS future NodeJS 8.9 NodeJS 9.2 NodeJS VNext ES6 ES7 ES8 And Michael Jackson… @sebastienpertus (from Microsoft  )
  • 2. ES6 / ES7 / ES2015 / ES2016 " ES7 is ES2016" " ES6 is ES2015 " " Too long for twitter … " " How many people here are going to say ES2016 " " Nobody, good ! "
  • 3. Ecmascript from past to future 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
  • 4. Where we are today
  • 5. ES6 : Where we are today • > 94% • > 96% in nighty builds http://kangax.github.io/compat-table/es6/
  • 6. ES7 : Where we are today Chakra SpiderMonkey V8 JavaScript Core Nighty builds
  • 8. Transpiler vs Compiler Transpiler is a specific term for taking source code written in one language and transforming into another language that has a similar level of abstraction Compiler 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
  • 16. And what about Node ?
  • 17. Node version Node.js 9.2.0 14/11/2017 Node.js 8.9.1 07/11/2017 Node.js 7.10.1 11/07/2017 Node.js 6.11.4 03/10/2017
  • 18. ES support : http://node.green/ • > 98% from node 7.5 +
  • 19. Enhancement Proposals : node-eps • https://github.com/nodejs/node-eps • Stream • ES modules • Url • Asynchronous API
  • 20. NodeJS CTC • Node.js Core Technical Committee & Collaborators • https://github.com/nodejs/CTC
  • 21. From Node 7.5 (with love) Not the future anymore… but maybe we should talk about …
  • 22. ES5 : Async Programming /* Callback Hell */ myFirstOperation(function(err, firstResult){ mySecondOperation(firstResult, function(err, secondResult){ myThirdOperation(secondResult, function(err, thirdResult){ /* HELL !!! */ }); }); });
  • 23. ES6 : Async Programming /* Promises */ var myFirstPromise = new Promise(function (resolve, reject) { // Do something var everyhtingIsOk = true; var result = { a: 12, b: "ok" }; if (everyhtingIsOk) { resolve(result); } else { reject(Error('Something went wrong')); } });
  • 24. ES6 : Async Programming /* Promises */ myFirstPromise() .then(firstResult => mySecondPromise(firstResult)) .then(secondResult => myThirdPromise(secondResult)) .then(thirdResult => { /* Code utilisant le 3ème résultat */ }).catch(err => { /* Gestion de l’erreur, quelque soit l’étape où elle a eu lieu */ });
  • 25. ES7 : Async Programming /* async await */ async function myOperations(){ const firstResult = await myFirstOperation(); const secondResult = await mySecondOperation(firstResult); const thirdResult = await myThirdOperation(secondResult); /* Code */ }; try { myOperations(); } catch (err) { /* Gestion de l’erreur, quelque soit l’étape où elle a eu lieu */ }
  • 28. Node 8 / NPM 5
  • 29. NPM 5.0.0 • --save by default • Autmaticaly create a package- lock.json • npm cache rewrited • You will have to ree-download all your package cache • npm fallback automaticaly to cache if no network • -- prefer-offline • -- prefer-online • -- offline • Large package download issue resolved
  • 32. Nouveautés Node 8 • Say hello to V8 5.8 • Forward compatibility with V8 5.9 and V8 6.0
  • 33. Node.js API (N-API) • 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/ )
  • 35. Node 8 : async_hooks 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) {}
  • 36. Node 8 : WHATWG URL Standard • 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());
  • 37. Node 8 : util.promisify() • 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) => {} 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(breeze);
  • 40. Les Modules CommonJS / AMD / ESM ?
  • 41. Modules in Browser • Safari 10.1 • Chrome canary 60 • Firefox 54 • Edge 15 With FLAGS https://jakearchibald.com/2017/es-modules-in-browsers/
  • 42. NodeJS modules : CommonJS • Synchronous • Evaluated during runtime
  • 43. ESM vs CJS export class person { getFullName() { return `${this.lastName} ${this.firstName}`; } } import * as people from './person'; var p = new people.person(); class person { getFullName() { return `${this.lastName} ${this.firstName}`; } } exports.person = person; const people = require("./person"); var p = new people.person();
  • 44. ESM modules in NodeJS • https://github.com/nodejs/node-eps/blob/master/002-es- modules.md • Implement interoperability for EcmaScript 6 modules (ESM) and Node’s existing module system (CJS) • Allow a common module syntax for Browser (ES6 spec) and Server side
  • 45. EF modules vs NodeJS modules • CommonJS is a dynamic loader modules system • Synchronous • Evaluated during runtime • ES is a static loader modules system • Asynchronous • Evaluated during parse time
  • 46. Example console.log('entry eval'); require('middle'); console.log('entry done); export {}; console.log('middle eval'); require('right'); console.log('middle done'); entry eval middle eval right eval right done middle done entry done export {}; console.log('right eval'); console.log('right done'); entry eval entry done middle eval middle done right eval right done sync async
  • 47. What Node wants to : Node wants to be able to : • Import a CJS module from ES (import from 'commonjs-module’ ) • Import a ESM module from CJS (require('es6-module’))
  • 48. ESM vs CJS. Solutions evaluated ? • Does Node.js want to ship a synchronous or asynchronous module loader? • Returning a promise (async) • Returning an object (sync) • Both ? • Multiple Solutions investigated: • Use CJS (require) for actuals .js files / Use ESM (import) with a newly file .mjs • Use a double parsing time • Config file • Obiwan Kenobi
  • 50. Detectiong CJS / ES Modules • https://github.com/nodejs/node/wiki/ES6-Module-Detection-in-Node • https://github.com/dherman/defense-of-dot-js/blob/master/proposal.md
  • 51. References • http://codeheroics.github.io/talks/nodemjs/ • https://medium.com/the-node-js-collection/an-update-on-es6-modules-in- node-js-42c958b890c • https://hackernoon.com/node-js-tc-39-and-modules-a1118aecf95e • https://medium.com/webpack/the-state-of-javascript-modules- 4636d1774358 • https://github.com/nodejs/node-eps/blob/master/002-es6-modules.md • https://github.com/nodejs/node-eps/issues/57 (mjs tradeoff) • http://2ality.com/2017/01/babel-esm-spec-mode.html • http://2ality.com/2017/05/es-module-specifiers.html
  • 52. Michael Jackson Script • Code compiler must know if it’s a CJS or ES module • In certain circumstance an import * from ‘foo’ could be a CJS module or an ES module (same syntax !) • Node.js will need to have some kind of mechanism for identifying in advance what kind of file is being loaded • foo.js will treat foo.js as CommonJS • bar.mjs will treat bar.mjs as an ESM Module. console.log(`Module load ${Date()}`)
  • 53. Or .. Changing ES Modules spec in ECMASCRIPT : • A module allways requires an import or an export • All modules are parsed. If it doesn't contain any of these statements, it is not an ES Module.
  • 54. Or … Would be recognized as a CommonJS module, while Would be an ES module. console.log(`Module load ${Date()}`) console.log(`Module load ${Date()}`) export{}
  • 55. But… •It works within Babel / Typescript !! •Under the hood, it’s just a transpilation to CJS Modules 
  • 56. Timeline • At the current point in time, there are still a number of specification and implementation issues that need to happen on the ES6 and Virtual Machine side of things before Node.js can even begin working up a supportable implementation of ES6 modules. Work is in progress but it is going to take some time — We’re currently looking at around a year at least. • Node V10 « around October 2018 » https://github.com/nodejs/Release
  • 57. ES6 : Modules (ESM) • TypeScript : Transpiling ESM Syntax in CommonJS modules • Node.js 9+ : Implementation with flags import {Person} from "./People"; import {Person, Material as M} from "./People"; import * as People from "./People"; import guy from './People';
  • 59. https://medium.com/web-on-the-edge/es-modules-in-node-today-32cff914e4b ES Modules in Node Today with polyfil @std/esm @std/esm Works from Node.js 4 Use *.mjs modules file extension

Editor's Notes

  • #9: Quand vous compilez du TypeScript, vous transformez votre code en JavaScript. Comme TypeScript est trés proche de JavaScript (ES6+), vous pouvez dire que vous Transpillez.
  • #16: Démo : Créer un nouveau projet TS avec Node Montrer l’intelissense Monter comment créer un server express rapidement npm install express npm install @types/express import * as express from 'express'; var app = express(); app.use("/", (req, res) => { res.send("Hello World"); }); app.listen(3000); Créer une classe Person pour montrer le passage de E5, ES6 dans TS export class Person{ firstName:string; lastName:string; constructor(fn:string, ln:string, public age=27){ this.firstName = fn; this.lastName = ln; } getFullName(){ return `Full name : ${this.firstName} ${this.lastName} ${this.age} ` } } Montrer comment on lance VS Code avec TS pour l’expérience de débuggage
  • #28: import fetch from 'node-fetch’; // Demo 1 créer un waiter à partir d'une promise async function wait(delay:number){ return new Promise((rs, rj) => { setTimeout(rs, delay); }); } // Démo : Ajouter node-fecth app.use("/", async (req, res) => { fetch('http://www.google.com').then((v) => { let responseText = `Hello ${p.getFullName()}<br /> ${v.statusText} `; res.send(responseText); }); })
  • #35: Lancer nvs et lancer chakra core Ajouter dans le rendu de la page [${process.execPath}]
  • #38: import * as util from "util"; declare module 'util' { export function promisify(fn: Function): (...args: any[]) => Promise<any>; } 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 breezeAsync = util.promisify(breeze);
  • #58: export class Person { firstName: string; lastName: string; constructor(fn: string, ln: string, public age = 27) { this.firstName = fn; this.lastName = ln; } getFullName() { return `Full name : ${this.firstName} ${this.lastName} ${this.age} ` } } export class Kid { } export class adzdazddadadzad { } export class people { kid = () => new Kid(); person = (fn, ln, age) => new Person(fn, ln, age); az = () => new Kid() } var pp = new people(); export default pp;
  • #59: export class Person { constructor(fn, ln, age = 27) { this.firstName = fn; this.lastName = ln; this.age = age; } getFullName() { return `Full name : ${this.firstName} ${this.lastName} ${this.age} ` } } export class Kid { } export class adzdazddadadzad { } export class people { person(fn, ln, age) { return new Person(fn, ln, age) } kid() { return new Kid() } ad() { return new adzdazddadadzad(); } } var pp = new people(); export default pp;