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

May 14, 2022
Tweet

More Decks by Yosuke Furukawa

Other Decks in Programming

Transcript

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

    View full-size slide

  2. Twitter: @yosuke_furukawa
    Github: yosuke-furukawa

    View full-size slide

  3. fetch
    (experimental)

    View full-size slide

  4. 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 full-size slide

  5. WHATWG Stream
    (experimental)

    View full-size slide

  6. 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 full-size slide

  7. Test Runner
    (experimental)

    View full-size slide

  8. 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 full-size slide

  9. userland snapshot

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  12. Node.js next 10

    View full-size slide

  13. 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 full-size 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 full-size slide

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

    View full-size slide

  16. Suitable Types / Document

    View full-size slide

  17. 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 full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  21. Single Executable Apps

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide