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

NodeFest2018/Node v10-v11

NodeFest2018/Node v10-v11

D76231a2114896dfcc7b79ac69558b79?s=128

Yosuke Furukawa
PRO

October 30, 2018
Tweet

Transcript

  1. NodeFest 2018 2018/10/30 @yosuke_furukawa

  2. NodeFest 2018 ։࠵͠·͢ʂʂʂʂ

  3. New Logo

  4. None
  5. Stickers, T-Shirts, Mugs are getting ready !!!

  6. Day1: Conference

  7. Featured Speakers

  8. None
  9. None
  10. None
  11. None
  12. None
  13. ͜ͷଞʹ΋

  14. None
  15. ॻ͖͖Εͳ͍΄Ͳίϯςϯπ͋Γ·͢ʂʂʂʂ

  16. Day2: Interactive Sessions

  17. Node/JS Discussion

  18. Node/JS Discussion

  19. Node/JS Discussion ΈΜͳͰҰॹʹ/PEF+4ͷྑ͍ͱ͜Ζɾѱ͍ͱ͜Ζɾ վળ఺Λॻ͖·͠ΐ͏

  20. Code And Learn

  21. Code And Learn ΈΜͳͰ/PEFKTʹ13ΛૹͬͯΈΔձ

  22. Code And Learn ݁Ռͱͯ͠ਓͷ/PEFίϛολʔΛ࡞Δ͜ͱ͕ग़ དྷ·ͨ͠ʂʂʂ

  23. Handson

  24. Handson

  25. Handson

  26. Handson

  27. Handson

  28. Handson

  29. After Party

  30. ࠓ೥΋͋Γ·͢ʂʂ Video Jockey!!!

  31. ΈΜͳདྷͯͶʂʂʂʂ http://bit.ly/nodefest2018-1 http://bit.ly/nodefest2018-2

  32. Node.js v10/v11
 ৘ใ 2018/10/30 @yosuke_furukawa

  33. CodeGrid ʹدߘத

  34. Node.js v10.0.0 ~ v10.12.0 • HTTP/2 • ES Modules •

    Error Code ʹΑΔϋϯυϦϯά • fs ʹ promises ͕௥Ճ͞Εͨ • Stream͕վળ͞Εͨ • Worker͕վળ͞Εͨ
  35. Node.js v11 • V8 version 7.0ରԠ (wasm վળ) • url

    module ͕ deprecated ʹͳΓɺ WHATWG URL Λར༻͢ΔΑ͏ʹ಺෦վળ͕ߦΘΕͨ • TextEncoder/TextDecoder͕globalʹͳͬͨ • queueMicrotask API ͕࣮ݧతʹ௥Ճ͞Εͨ
  36. Stream/Promiseͷ਌࿨ੑվળ • for await of Ͱ Stream Λஞ࣍ॲཧͰ͖ΔΑ͏ ʹͳͬͨ •

    Node v10 ͔Β Stream ʹ௥Ճ͞Εͨ finished, pipeline API͕ Promiseͱͷ਌࿨ੑߴ͍
  37. for await of ͷվળ const fs = require('fs'); async function

    print(readable) { readable.setEncoding('utf8'); let data = ''; // for await ۟Ͱiterateͭͭ͠ɺchunkΛऔΓग़͢ for await (const k of readable) { data += k; } console.log(data); } print(fs.createReadStream('file')).catch(console.log);
  38. Stream finished API const fs = require('fs'); const { finished

    } = require('stream'); const rs = fs.createReadStream('./stream.js'); //finished API ͰΤϥʔऴྃɺਖ਼ৗऴྃʹ͔͔ΘΒͣऴྃͨ͠ΒίʔϧόοΫΛݺ΂Δɻ finished(rs, (err) => { if (err) { console.error('Stream failed', err); return; } console.log('Stream is done reading'); }); rs.resume();
  39. Stream finished API const fs = require('fs'); const util =

    require('util'); const stream = require('stream'); // Promisify Λ࢖ͬͯcallbackΛpromiseʹ͢Δ const finished = util.promisify(stream.finished); const rs = fs.createReadStream('./stream.js'); // async await ͕࢖͑Δ async function run() { await finished(rs); console.log('Stream is done reading'); } run().catch((err) => console.error('Stream failed', err)); rs.resume();
  40. Stream Pipeline API const fs = require('fs'); const rs =

    fs.createReadStream('error.txt'); const ws = fs.createWriteStream('output.txt'); rs.pipe(ws).on("error", (e) => { // ͜͜Ͱ౷ҰతʹΤϥʔΛϋϯυϦϯά͍͕ͨ͠ɺ // readstreamͰΤϥʔʹͳΔͱ͜͜ʹདྷͳ͍ɻ // ͜͏΍ͬͯॻ͔ͳͯ͘͸͍͚ͳ͍ // rs.on("error", errorHandler).pipe(ws).on("error", errorHandler) });
  41. Stream Pipeline API const { pipeline, Transform } = require('stream');

    const rs = fs.createReadStream('./stream.js'); const ts = new Transform({ transform(chunk, encoding, callback) { callback(null, chunk.toString().toUpperCase()) } }); const ws = fs.createWriteStream('./stream_cap.js'); pipeline(rs, ts, ws, (err) => { if (err) { console.error(err); return; } console.log('Stream is done reading'); }); rs.resume();
  42. Stream Pipeline API const { pipeline, Transform } = require('stream');

    const p = util.promisify(pipeline); const rs = fs.createReadStream('./stream.js'); const ts = new Transform({ transform(chunk, encoding, callback) { callback(null, chunk.toString().toUpperCase()) } }); const ws = fs.createWriteStream('./stream_cap.js'); // promisify ͔ͯ͠Β async-awaitͰ͖Δ async function run() { await p(rs, ts, ws); console.log('Stream is done reading'); } run().catch(console.error); rs.resume();
  43. Promise ଆ΋͍͔ͭ͘վળ • Promise͕ෳ਺ճresolve, reject͞Εͨͱ͖ʹ ϋϯυϦϯά͢Δɺ multipleResolves ͕௥Ճ • queueʹ௚઀MicrotaskΛੵΉɺ

    queueMicrotask API ͕௥Ճ͞Εͨɻ
  44. process.on('multipleResolves ') process.on('multipleResolves', (type, promise, reason) => { console.error(type, promise,

    reason); setImmediate(() => process.exit(1)); }); async function main() { try { return await new Promise((resolve, reject) => { resolve('First call'); resolve('Swallowed resolve'); reject(new Error('Swallowed reject')); }); } catch { throw new Error('Failed'); } }
  45. queueMicrotask DataHandler.prototype.load = async function load(key) { const hit =

    this._cache.get(url); if (hit !== undefined) { queueMicrotask(() => { this.emit('load', hit); }); return; } const data = await fetchData(key); this._cache.set(url, data); this.emit('load', data); };
  46. Why Node needs web standard? James Snell @ NodeFest 2016


    Node.js is, and has been, primarily a platform for Web Application Development While Node.js presumes a "small core" philosophy for most things, it includes support for the most basic and critical internet standards
  47. None