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

Node.js 最新動向 TFCon 2022

Node.js 最新動向 TFCon 2022

TFCon で発表する Node.js 最新動向です。

Yosuke Furukawa
PRO

May 14, 2022
Tweet

More Decks by Yosuke Furukawa

Other Decks in Programming

Transcript

  1. ݹ઒ཅհ
    /PEFKT࠷৽ಈ޲
    !5FDI'FFE$POGFSFODF

    View Slide

  2. Twitter: @yosuke_furukawa
    Github: yosuke-furukawa

    View Slide

  3. Node.js v18

    View Slide

  4. fetch
    (experimental)

    View Slide

  5. Fetch Example
    const res = await fetch('https://nodejs.org/api/documentation.json');
    if (res.ok) {
    const data = await res.json();
    console.log(data);
    }
    // $ node fetch.mjs

    {
    type: 'module',
    source: 'doc/api/documentation.md',
    introduced_in: 'v0.10.0',
    ...
    }

    View Slide

  6. WHATWG Stream
    (experimental)

    View Slide

  7. WHATWG Stream example
    import {
    ReadableStream
    } from 'node:stream/web';
    import {
    setInterval as every
    } from 'node:timers/promises';
    import {
    performance
    } from 'node:perf_hooks';
    const stream = new ReadableStream({
    async start(controller) {
    for await (const _ of every(1000))
    controller.enqueue(performance.now());
    }
    });
    for await (const value of stream)
    console.log(value);

    View Slide

  8. Test Runner
    (experimental)

    View Slide

  9. Test Runner Example
    import test from 'node:test';
    import assert from 'node:assert';
    test('top level test', async (t) => {
    await t.test('subtest 1', (t) => {
    assert.strictEqual(1, 1);
    });
    await t.test('subtest 2', (t) => {
    assert.strictEqual(2, 2);
    });
    });
    $ node test.mjs

    TAP version 13
    ok 1 - subtest 1
    ---
    duration_ms: 0.000283375

    View Slide

  10. userland snapshot

    View Slide

  11. userland snapshot
    • bootstrap ࣌ʹେ͖͍ϑΝΠϧΛಡΈࠐ·ͳ͍ͱ͍͚ͳ
    ͍৔߹ʹىಈ͕஗͘ͳΔʢྫ: TypeScriptΛಡΈࠐΉʣɻ
    • ͢ͰʹಡΈࠐΜͩঢ়ଶͰΠϝʔδΛ࡞͓͖͍ͬͯͨ
    • ͜Ε͕Ͱ͖Δͷ͕ userland snapshot
    • Node.js build ࣌ʹಡΈࠐ·ͤΔ `./configure --node-
    snapshot-main=typescript-bootstrap.js && make`

    View Slide

  12. 5/27 Node.js 13th Birthday
    🎂 🎉🎉🎉

    View Slide

  13. Node.js next 10

    View Slide

  14. Next 10 Milestones
    • Modern HTTP
    • Suitable Types for End
    Users
    • Documentation
    • Web Assembly
    • ESM
    • Latest ECMAScript Spec
    • Observability
    • Permissions
    • Better Multithread
    • Single Executable
    Applications

    View Slide

  15. Next 10 Milestones
    • Modern HTTP
    • Suitable Types for End
    Users
    • Documentation
    • Web Assembly
    • ESM
    • Latest ECMAScript Spec
    • Observability
    • Permissions
    • Better Multithread
    • Single Executable
    Applications

    View Slide

  16. Modern HTTP

    View Slide

  17. Modern HTTP
    • http 1 / 2 [already supported]
    • fetch [experimentally supported]
    • http3 ˒ next target

    View Slide

  18. Suitable Types / Document

    View Slide

  19. Fetch Example
    const res = await fetch('https://nodejs.org/api/documentation.json');
    if (res.ok) {
    const data = await res.json();
    console.log(data);
    }
    // $ node fetch.mjs

    {
    type: 'module',
    source: 'doc/api/documentation.md',
    introduced_in: 'v0.10.0',
    ...
    }

    View Slide

  20. ઈରؾ͍ͮͯͳ͍ϙΠϯτ
    fetch("https://nodejs.org/api/documentation.json")
    ͜ͷURLؾ͍ͮͯΔ...?

    View Slide

  21. fetch('https://nodejs.org/api/documentation.json')
    • ͜ͷURL͸Node.jsͷυΩϡϝϯτΛJSONʹͨ͠΋ͷ
    • ࣮͸APIҎԼͷdocs͸HTMLʹ΋ͳͬͯΔ͠ɺશ෦JSONʹ
    ΋ͳͬͯΔɻ(/api/fs.json ͱ͔ /api/http.json ΋͋Δ)
    • ͚ͩ͜͜ͷ৘ใͩͱͨͩͷʮ΁ʔʯͰऴྃ
    • ࣮͸Ҿ਺ύϥϝʔλͱ͔໭Γ஋ͱ͔ͷܕ΋JSON͔ΒऔΕΔ
    • ͔ͬ͜Βܕ৘ใੜ੒Ͱ͖ΔΑ͏ͳ৘ใ͕औΕΔɻ

    View Slide

  22. Types / Document
    • ܕ৘ใ͸ԿΒ͔ͷํ๏ͰΤϯυϢʔβʔʹಧ
    ͚Δ
    • ·ͣ͸ܕ৘ใΛϓϩάϥϚ͕Ճ޻͠΍͍͢ܗ
    Ͱಧ͚Δ
    • ಛఆͷݴޠʹಛԽͨ͠৘ใ΋ಧ͚Δ͔Ͳ͏͔
    ͸Ϣʔβʔͷ੠࣍ୈ

    View Slide

  23. Single Executable Apps

    View Slide

  24. Single Executable Apps
    • ࠓͷ Node.js ΞϓϦέʔγϣϯ͸ϦϦʔεɾσϓϩΠʹ࣌
    ͕͔͔ؒΔ
    • docker ౳Ͱ΍Δͱຖճ npm install => typescript compile
    => bundle ͱͳΔ
    • ୯Ұͷ࣮ߦՄೳͳϑΝΠϧΛ࡞ΓɺͦΕΛ഑ஔ͢Δ͚ͩͰ
    σϓϩΠͰ͖ΔΑ͏ʹ͢Δ
    • ·ͩݱ࣌఺Ͱ͸ draft ஈ֊ɺࠓޙʹظ଴

    View Slide

  25. Node.js ͷϢʔβʔ͸
    ଟछଟ༷

    View Slide

  26. ͨͩ͠େ͖͘෼͚Δͱ2छྨ
    Application
    Developer
    Site Reliability
    Engineer

    View Slide

  27. ྆ऀͷࢥ࿭
    Application
    Developer
    Site Reliability
    Engineer
    ৽͍͠ػೳΛ࢖͍͍ͨ
    Ͱ͖Δ͜ͱΛ૿΍͍ͨ͠
    ։ൃऀମݧΛ্͍͛ͨ

    View Slide

  28. ྆ऀͷࢥ࿭
    Application
    Developer
    Site Reliability
    Engineer
    ৽͍͠ػೳΛ࢖͍͍ͨ
    Ͱ͖Δ͜ͱΛ૿΍͍ͨ͠
    ։ൃऀମݧΛ্͍͛ͨ
    ϒϥ΢β౳ଞͷ8FCϓϥοτϑΥʔ
    Ϝͱͷޓ׵ੑΛ্͛ͯ΄͍͠

    View Slide

  29. ྆ऀͷࢥ࿭
    Application
    Developer
    Site Reliability
    Engineer
    Ϗϧυ΍σϓϩΠΛ҆ఆ͍ͤͨ͞
    ੑೳΛ༧ଌͰ͖ΔΑ͏ʹ͍ͨ͠
    ϞχλϦϯά΍਍அՄೳʹ͍ͨ͠

    View Slide

  30. ྆ऀͷࢥ࿭
    Application
    Developer
    Site Reliability
    Engineer
    Ϗϧυ΍σϓϩΠΛ҆ఆ͍ͤͨ͞
    ੑೳΛ༧ଌͰ͖ΔΑ͏ʹ͍ͨ͠
    ϞχλϦϯά΍਍அՄೳʹ͍ͨ͠
    ,VCFSOFUFT౳ίϯςφٕज़ͱͷ਌
    ࿨ੑ޲্

    View Slide

  31. ྆ऀͷχʔζΛ׎͑Δඞཁ͕
    ͋Δ

    View Slide

  32. ࣍ͷ Node.js 10೥Λݟਾ͑ͯ
    ͷ׆ಈத

    View Slide

  33. Thanks

    View Slide