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

Node.jsの2022年と未来 / Node.js in 2022 and Future

Node.jsの2022年と未来 / Node.js in 2022 and Future

Node.js v18とv19の主な変更点や今後について発表しました。

Masashi Hirano

November 16, 2022
Tweet

More Decks by Masashi Hirano

Other Decks in Programming

Transcript

  1. Node.jsͷ2022೥ͱະདྷ
    Node.js v18, v19ͷओͳมߋ఺ͱࠓޙ௥Ճ͞ΕΔػೳʹ͍ͭͯ
    Masashi Hirano (@shisama)

    View full-size slide

  2. ฏ໺ ণ࢜ / Masashi Hirano
    Frontend Developer


    @shisama_


    shisama


    Node.js Core Collaborator


    View full-size slide

  3. Agenda
    • Node.js v18ͷओͳมߋ఺


    • Node.js v19ͷओͳมߋ఺


    • ݱࡏ࣮૷தͷػೳ͔ΒPick Up


    • Next 10 years

    View full-size slide

  4. Node.js in 2022

    View full-size slide

  5. Node.js v18
    • 2022/04/19ɺv18.0.0ϦϦʔε


    • 2022/10/25ɺv18.12.0͕LTSͱͯ͠ϦϦʔε


    • 2025/04/30ɺϝϯςφϯεऴྃ༧ఆ

    View full-size slide

  6. fetch()
    • ϒϥ΢βͷfetch()ؔ਺͕࣮ߦ࣌ϑϥάͳ͠Ͱ΋࢖༻Մೳ


    • HTTPͷϦΫΤετΛૹ৴͢Δؔ਺


    • ·ͩExperimental


    • ϒϥ΢βͱಉ͡Α͏ʹάϩʔόϧؔ਺ͱͯ͠࢖༻Մೳ

    View full-size slide

  7. ςετϥϯφʔͷ௥Ճ
    • Jest΍VitestͷΑ͏ͳςετϥϯφʔ͕Node.jsຊମʹ΋௥Ճ͞Εͨ


    • ‘node:test’͔Βimportͯ͠࢖͏


    • ͰςετΛ࣮ߦ


    • ΦϓγϣϯͰskipͳͲΛࢦఆՄೳ

    View full-size slide

  8. V8 (JSΤϯδϯ) ͕όʔδϣϯΞοϓ
    • ϝδϟʔόʔδϣϯ্͕͕ΔλΠϛϯάͰV8͕ߋ৽͞ΕΔ


    • Node.js v18 Ͱ͸ V8͕10.1ʹόʔδϣϯΞοϓ


    • Array#
    fi
    ndLast()΍ɺ

    Intl.supportedValuesOf()͕

    ࢖͑ΔΑ͏ʹͳͬͨ

    View full-size slide

  9. HTTP requestTimeout()ͷσϑΥϧτ஋ͷมߋ
    • server.requetTimeoutͷλΠϜΞ΢τ࣌ؒͷσϑΥϧτ஋͕

    0 ͔Β 300000ϛϦඵ (5෼) ʹͳΓ·ͨ͠ɻ


    • http.createServer({ requestTimeout: 600000 })ͷΑ͏ʹࢦఆ͢Δ͜ͱ΋Ͱ
    ͖Δ͕ɺ0 Λࢦఆ͢Δ͜ͱ͸ඇਪ঑


    • 0 ͸λΠϜΞ΢τͳ͠ʹͳΔͨΊɺॲཧ͕௕͍ϦΫΤετͷ׬ྃΛ଴ͬ
    ͨΓDoS߈ܸ͞ΕͨΒ߈ܸ͕ऴΘΒͳ͍ݶΓϦΫΤετ଴͕ͪൃੜ͢Δ

    View full-size slide

  10. Web Streams API
    • ϒϥ΢βʢWebʣͷStream APIͱಉ͡ΠϯλʔϑΣʔε΍࢓༷ʹԊͬ
    ͨ Stream ͷ API


    • Node.jsͷݹ͍Streamͱ͸ޓ׵ੑͳ͠


    • Node.js v18͔Βϑϥάͳ͠Ͱ

    ࢖༻Մೳʹͳ͕ͬͨ·ͩExperimental

    View full-size slide

  11. —watch
    • Webpack ͳͲͰ͓ͳ͡ΈͷwatchϞʔυ͕Node.jsຊମʹ΋ೖͬͨ


    • ࣮ߦதͷϓϩάϥϜͷґଘؔ܎ʹ͋ΔϞδϡʔϧʹมߋ͕͋ͬͨΒࣗ
    ಈతʹϓϩηε͕࠶ىಈ͢Δ


    • node index.js —watch ͷΑ͏ʹ

    —watchϑϥάΛ͚ͭͯىಈ͢Δ


    • v18.11.0͔Β࢖͑Δ

    View full-size slide

  12. HTTP(S) KeepAlive ͕σϑΥϧτͰ༗ޮʹ
    • ϦΫΤετΛૹ৴͢Δͱ͖ͷ Keep-Alive ͕σϑΥϧτ༗ޮʹมߋ


    • Keep-Alive ͕༗ޮʹͳΔͱɺҰఆ࣌ؒ઀ଓ͕ҡ࣋͞ΕΔͨΊϋϯυγΣ
    ΠΫͷճ਺͕ݮͬͯύϑΥʔϚϯε͕Α͘ͳΔ


    • ͜Ε·Ͱ௨Γ໌ࣔతʹࢦఆ͢Δ͜ͱ΋Մೳ
    const http = require('node:http');


    const agent = new http.Agent({ keepAlive: true });


    const req = http


    .get('http://localhost:3000', { agent }, (res) => {


    // ...


    })

    View full-size slide

  13. V8(JSΤϯδϯ)ͷόʔδϣϯΞοϓ
    • V8͕10.7ʹΞοϓσʔτ͞Εͨ͜ͱͰJSͷ৽ػೳ͕૿͑ͨ


    • Intl.NumberFormat v3 (https://github.com/tc39/proposal-intl-
    numberformat-v3)


    • ൣғΛϑΥʔϚοτΛ

    ͢ΔformatRange()

    View full-size slide

  14. --experimental-speci
    fi
    er-resolution ϑϥάͷ࡟আ
    • import ‘./foo’; ͱॻ͖͍ͨ৔߹ɺ—experimental-speci
    fi
    er-
    resolution=nodeϑϥάΛ͚࣮ͭͯߦ͢Ε͹ิ׬ͯ͘͠Ε͍ͯͨ


    • ESM͸࢓্༷ɺ֦ுࢠͷলུ͕ڐ͞Ε͍ͯͳ͍


    • import xxx from ‘./foo’ ͱ͸ॻ͚ͳ͍ɻ’./foo.js’ͱ͠ͳ͚Ε͹ͳΒͳ͍


    • ୅ସखஈˠCustom LoaderΛ࡞Δ



    View full-size slide

  15. https://github.com/nodejs/loaders-test
    nodejs/loaders-test ʹCustom Loaderͷαϯϓϧ͕͋Δ

    View full-size slide

  16. Web Crypto API ͕ stable ʹ
    • ϒϥ΢β(Web)ͷ Crypto API ͱΠϯ
    λʔϑΣʔεޓ׵͕͋Δ


    • Node.jsͷݹ͍Crypto APIͱޓ׵͸ͳ͍


    • ҉߸Խ΍෮߸Λ͢Δ͜ͱ͕Ͱ͖ΔAPI

    View full-size slide

  17. ShadowRealm
    • JavaScriptΛ࣮ߦ͢ΔͨΊͷάϩʔόϧ؀ڥʢRealmʣΛ৽͘͠ੜ੒͢ΔAPI


    • ҟͳΔίϯςΩετͷͨΊɺάϩʔόϧ؀ڥ͕Ԛછ͞Εͳ͍


    • αϯυϘοΫε؀ڥΛ࡞Δ͜ͱ͕Ͱ͖Δ


    • ݱࡏ ECMAScriptͷproposal stage 3


    • Node.jsͷvm APIͰ΋ಉ͜͡ͱ͸Ͱ͖Δ

    ͕ɺϒϥ΢β(Web)ޓ׵ͱ͍͏ͷ͕ϙΠϯτ


    • ·ͩExperimental

    View full-size slide

  18. https://zenn.dev/petamoriken/articles/6656b387555610

    View full-size slide

  19. https://shisama.hatenablog.com/
    ঺հͰ͖ͳ͔ͬͨओͳมߋ఺ʹ͍ͭͯ͸ϒϩά΋ಡΜͰ͍ͩ͘͞

    View full-size slide

  20. Node.js in future

    View full-size slide

  21. ݱࡏ࣮૷தͷػೳ͔ΒPick Up

    View full-size slide

  22. node:test ϞοΫͷػೳ
    • https://github.com/nodejs/node/pull/45326 (Ϛʔδࡁ)


    • mock.fnɺmock.methodɺmock.restoreͳͲͷϞοΫؔ਺͕
    node:testʹ௥Ճ͞Εͨ import { mock, test } from 'node:test';
    import assert from 'node:assert';
    test(‘should call callback function’, () => {
    const mockCallback = mock.fn((uuid) => {
    return uuid;
    })
    assert.strictEqual(mockCallback.mock.calls.length, 0);
    uuid(mockCallback);
    assert.strictEqual(mockCallback.mock.calls.length, 1);
    });

    View full-size slide

  23. node:http/static (੩తϑΝΠϧ༻ͷHTTPαʔό)
    • https://github.com/nodejs/node/pull/45096 (ొஃ࣌Ͱ͸ະϚʔδ)


    • ੩తϑΝΠϧΛ഑৴͢ΔαʔόΛىಈ͢Δ͜ͱ͕Ͱ͖Δ


    • ͷ୅ସʹ࢖༻Ͱ͖Δ


    • Node.js ຊମ͚ͩͰىಈͰ͖Δͷ͕ར఺

    View full-size slide

  24. QUIC
    • https://github.com/nodejs/node/pull/44325 (ొஃ࣌Ͱ͸ະϚʔδ)


    • QUIC ͸τϥϯεϙʔτϓϩτίϧ


    • σʔλ࠶ૹͷޮ཰Խɺ௨৴ͷܧଓੑɺ಺෦తʹTLSΛར༻ͯ͠҉߸Խ
    ͳͲͷಛ௃͕͋Δ


    • HTTP/3͸QUICͷ্Ͱಈ͘
    https://datatracker.ietf.org/meeting/98/materials/slides-98-edu-sessf-quic-tutorial/

    View full-size slide

  25. https://gihyo.jp/admin/serial/01/http3/0001

    View full-size slide

  26. Single Executable Application
    • https://github.com/nodejs/node/pull/45038 (ొஃ࣌Ͱ͸ະϚʔδ)


    • JS͔Β୯ҰͷωΠςΟϒͷ࣮ߦϑΝΠϧ΁ม׵


    • e.g. Windowsͷ.exeϑΝΠϧ


    • JSͰॻ͍ͨΞϓϦέʔγϣϯΛNode.js͕Πϯετʔϧ͞Ε͍ͯͳ͍
    ؀ڥͰ΋࣮ߦͰ͖ΔΑ͏ʹͳΔ


    • ݱࡏͷ୅ସखஈͱͯ͠͸vercel/pkg͕͋Δ


    • https://github.com/nodejs/single-executable Ͱ׆ಈ͞Ε͍ͯΔ
    +4 +4
    +4 +4
    &9&
    ·ͱΊͯ̍ͭͷ

    ࣮ߦϑΝΠϧ΁

    View full-size slide

  27. ύʔϛογϣϯϞσϧ
    • https://github.com/nodejs/node/pull/44004 (ొஃ࣌Ͱ͸·ͩDraft)


    • DenoͷΑ͏ʹ࣮ߦ࣌ʹύʔϛογϣϯΛ෇༩͢Δ͜ͱͰϑΝΠϧΞ
    Ϋηε΍ϓϩηεͷىಈͳͲΛ੍ޚͯ͠ηΩϡΞͳ࣮ߦΛՄೳʹ͢Δ


    • ·ͩͲ͏͍͏ܗࣜʹ͢Δ͔΋ٞ࿦த


    • Denoͷ `—allow-…`ͷΑ͏ʹڐՄܗࣜʹ͢Δ͔ɺ

    `—deny-…`ͷΑ͏ʹېࢭܗࣜʹ͢Δ͔΋ܾ·͍ͬͯͳ͍

    View full-size slide

  28. Next 10 years

    View full-size slide

  29. next-10
    • Node.js ͷࠓޙ10೥Ͳ͏͢Δ͔ͷٞ࿦͕͞Ε͍ͯΔ


    • https://github.com/nodejs/next-10


    • ϦϙδτϦ಺ͷ TECHNICAL_PRIORITY_WORKING_SUMMARY.mdʹ

    ༏ઌ౓ͷߴ͍ػೳͷҰཡͱؔ࿈ϦϯΫ͕ܝࡌ͞Ε͍ͯΔ


    • nodejs/node ϦϙδτϦ಺ͷ doc/contributing/technical-priorities.md ʹ
    ༏ઌ౓ͷߴ͍ػೳͷ֓ཁ͕ܝࡌ͞Ε͍ͯΔ


    • ࣮૷͞Ε࢝Ί͍ͯΔ΋ͷ΋͋Δ͕ٞ࿦தͷ΋ͷ΋ଟ͍

    View full-size slide

  30. https://github.com/nodejs/node/blob/HEAD/doc/contributing/technical-priorities.md
    next-10Ͱ༏ઌతͳػೳͷ֓ཁ͕ه͞Ε͍ͯΔ

    View full-size slide

  31. Technical Priorities
    • Modern HTTP


    • Suitable types for end-users


    • Documentation


    • WebAssembly


    • ESM
    • Support for features from the
    latest ECMAScript spec


    • Observability


    • Permissions/policies/sec model


    • Better multithreaded support


    • Single Executable Applications

    View full-size slide

  32. Suitable types for end-users
    • ϝϯςφϒϧͰ৴པ౓ͷߴ͍ܕ৘ใΛϢʔβʔʹఏڙ͍ͨ͠


    • ݱࡏߟ͍͑ͯΔܕ৘ใΛఏڙ͢ΔͨΊͷΞϓϩʔν


    • APIΛ௥Ճ͢Δͱ͖ʹMarkdownͰॻ͔ΕͨNode.jsͷAPIͷυΩϡϝϯτΛ௥Ճ


    • MarkdownͰॻ͔ΕͨAPIͷυΩϡϝϯτ͔ΒϚγϯϦʔμϒϧͳJSONΛࣗಈੜ੒


    • ͦͷJSON͔Βܕ৘ใΛੜ੒͢Δ


    • Maintaining types for Node.js (https://github.com/nodejs/node/blob/main/doc/
    contributing/maintaining-types-for-nodejs.md) ʹৄࡉ͕ܝࡌ͞Ε͍ͯΔ

    View full-size slide

  33. Support for features from the latest ECMAScript spec
    • ࠷৽ͷECMAScriptͷ࢓༷Λαϙʔτ͍ͨ͠


    • ESͷ࢓༷௥ਵ͸V8(JSΤϯδϯ)ͷߋ৽ʹΑͬͯߦΘΕ͍ͯΔ


    • ݱࡏ͸V8ͷߋ৽͕ϝδϟʔόʔδϣϯͷͱ͖ͷΈߦΘΕ͍ͯΔ


    • ·ͩํ๏͸ະఆ͕ͩ࢓༷௥ਵͷͨΊʹݱࡏͷํ๏Λม͑Δඞཁ͕͋Δ

    View full-size slide

  34. ·ͱΊ
    • Node.js v18ͱv19ʹ͸fetch΍Web Streams APIͳͲWebޓ׵ͳػೳ
    ͕ϑϥάͳ͠Ͱ࢖͑ͨΓstableʹͳͬͨ


    • ςετϥϯφʔ΍watchϞʔυͳͲ։ൃମݧΛ޲্ͤ͞ΔͨΊͷػೳ
    ΋௥Ճ͞Εͨ


    • Node.jsͷ࣍ͷ10೥ʹ޲͚ͯٞ࿦͕։࢝͞Ε͍ͯΔ


    • ༏ઌ౓͕ߴ͍ػೳ͔Β࣮૷΍ٞ࿦͕࢝·͍ͬͯΔ

    View full-size slide

  35. https://jsconf.jp
    JSConf JPͰ΋Node.jsʹ͍ͭͯͷτʔΫ͕͋Γ·͢ʂ

    View full-size slide