$30 off During Our Annual Pro Sale. View Details »

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)

  2. ฏ໺ ণ࢜ / Masashi Hirano Frontend Developer @shisama_ shisama Node.js

    Core Collaborator
  3. Agenda • Node.js v18ͷओͳมߋ఺ • Node.js v19ͷओͳมߋ఺ • ݱࡏ࣮૷தͷػೳ͔ΒPick Up

    • Next 10 years
  4. Node.js in 2022

  5. Node.js v18

  6. Node.js v18 • 2022/04/19ɺv18.0.0ϦϦʔε • 2022/10/25ɺv18.12.0͕LTSͱͯ͠ϦϦʔε • 2025/04/30ɺϝϯςφϯεऴྃ༧ఆ

  7. fetch() • ϒϥ΢βͷfetch()ؔ਺͕࣮ߦ࣌ϑϥάͳ͠Ͱ΋࢖༻Մೳ • HTTPͷϦΫΤετΛૹ৴͢Δؔ਺ • ·ͩExperimental • ϒϥ΢βͱಉ͡Α͏ʹάϩʔόϧؔ਺ͱͯ͠࢖༻Մೳ

  8. ςετϥϯφʔͷ௥Ճ • Jest΍VitestͷΑ͏ͳςετϥϯφʔ͕Node.jsຊମʹ΋௥Ճ͞Εͨ • ‘node:test’͔Βimportͯ͠࢖͏ • ͰςετΛ࣮ߦ • ΦϓγϣϯͰskipͳͲΛࢦఆՄೳ

  9. V8 (JSΤϯδϯ) ͕όʔδϣϯΞοϓ • ϝδϟʔόʔδϣϯ্͕͕ΔλΠϛϯάͰV8͕ߋ৽͞ΕΔ • Node.js v18 Ͱ͸ V8͕10.1ʹόʔδϣϯΞοϓ

    • Array# fi ndLast()΍ɺ 
 Intl.supportedValuesOf()͕ 
 ࢖͑ΔΑ͏ʹͳͬͨ
  10. HTTP requestTimeout()ͷσϑΥϧτ஋ͷมߋ • server.requetTimeoutͷλΠϜΞ΢τ࣌ؒͷσϑΥϧτ஋͕ 
 0 ͔Β 300000ϛϦඵ (5෼) ʹͳΓ·ͨ͠ɻ

    • http.createServer({ requestTimeout: 600000 })ͷΑ͏ʹࢦఆ͢Δ͜ͱ΋Ͱ ͖Δ͕ɺ0 Λࢦఆ͢Δ͜ͱ͸ඇਪ঑ • 0 ͸λΠϜΞ΢τͳ͠ʹͳΔͨΊɺॲཧ͕௕͍ϦΫΤετͷ׬ྃΛ଴ͬ ͨΓDoS߈ܸ͞ΕͨΒ߈ܸ͕ऴΘΒͳ͍ݶΓϦΫΤετ଴͕ͪൃੜ͢Δ
  11. Web Streams API • ϒϥ΢βʢWebʣͷStream APIͱಉ͡ΠϯλʔϑΣʔε΍࢓༷ʹԊͬ ͨ Stream ͷ API

    • Node.jsͷݹ͍Streamͱ͸ޓ׵ੑͳ͠ • Node.js v18͔Βϑϥάͳ͠Ͱ 
 ࢖༻Մೳʹͳ͕ͬͨ·ͩExperimental
  12. —watch • Webpack ͳͲͰ͓ͳ͡ΈͷwatchϞʔυ͕Node.jsຊମʹ΋ೖͬͨ • ࣮ߦதͷϓϩάϥϜͷґଘؔ܎ʹ͋ΔϞδϡʔϧʹมߋ͕͋ͬͨΒࣗ ಈతʹϓϩηε͕࠶ىಈ͢Δ • node index.js

    —watch ͷΑ͏ʹ 
 —watchϑϥάΛ͚ͭͯىಈ͢Δ • v18.11.0͔Β࢖͑Δ
  13. Node.js v19

  14. 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) => { // ... })
  15. V8(JSΤϯδϯ)ͷόʔδϣϯΞοϓ • V8͕10.7ʹΞοϓσʔτ͞Εͨ͜ͱͰJSͷ৽ػೳ͕૿͑ͨ • Intl.NumberFormat v3 (https://github.com/tc39/proposal-intl- numberformat-v3) • ൣғΛϑΥʔϚοτΛ

    
 ͢ΔformatRange()
  16. --experimental-speci fi er-resolution ϑϥάͷ࡟আ • import ‘./foo’; ͱॻ͖͍ͨ৔߹ɺ—experimental-speci fi er-

    resolution=nodeϑϥάΛ͚࣮ͭͯߦ͢Ε͹ิ׬ͯ͘͠Ε͍ͯͨ • ESM͸࢓্༷ɺ֦ுࢠͷলུ͕ڐ͞Ε͍ͯͳ͍ • import xxx from ‘./foo’ ͱ͸ॻ͚ͳ͍ɻ’./foo.js’ͱ͠ͳ͚Ε͹ͳΒͳ͍ • ୅ସखஈˠCustom LoaderΛ࡞Δ •
  17. https://github.com/nodejs/loaders-test nodejs/loaders-test ʹCustom Loaderͷαϯϓϧ͕͋Δ

  18. Web Crypto API ͕ stable ʹ • ϒϥ΢β(Web)ͷ Crypto API

    ͱΠϯ λʔϑΣʔεޓ׵͕͋Δ • Node.jsͷݹ͍Crypto APIͱޓ׵͸ͳ͍ • ҉߸Խ΍෮߸Λ͢Δ͜ͱ͕Ͱ͖ΔAPI
  19. ShadowRealm • JavaScriptΛ࣮ߦ͢ΔͨΊͷάϩʔόϧ؀ڥʢRealmʣΛ৽͘͠ੜ੒͢ΔAPI • ҟͳΔίϯςΩετͷͨΊɺάϩʔόϧ؀ڥ͕Ԛછ͞Εͳ͍ • αϯυϘοΫε؀ڥΛ࡞Δ͜ͱ͕Ͱ͖Δ • ݱࡏ ECMAScriptͷproposal

    stage 3 • Node.jsͷvm APIͰ΋ಉ͜͡ͱ͸Ͱ͖Δ 
 ͕ɺϒϥ΢β(Web)ޓ׵ͱ͍͏ͷ͕ϙΠϯτ • ·ͩExperimental
  20. https://zenn.dev/petamoriken/articles/6656b387555610

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

  22. Node.js in future

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

  24. 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); });
  25. node:http/static (੩తϑΝΠϧ༻ͷHTTPαʔό) • https://github.com/nodejs/node/pull/45096 (ొஃ࣌Ͱ͸ະϚʔδ) • ੩తϑΝΠϧΛ഑৴͢ΔαʔόΛىಈ͢Δ͜ͱ͕Ͱ͖Δ • ͷ୅ସʹ࢖༻Ͱ͖Δ •

    Node.js ຊମ͚ͩͰىಈͰ͖Δͷ͕ར఺
  26. 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/
  27. https://gihyo.jp/admin/serial/01/http3/0001

  28. 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& ·ͱΊͯ̍ͭͷ 
 ࣮ߦϑΝΠϧ΁
  29. ύʔϛογϣϯϞσϧ • https://github.com/nodejs/node/pull/44004 (ొஃ࣌Ͱ͸·ͩDraft) • DenoͷΑ͏ʹ࣮ߦ࣌ʹύʔϛογϣϯΛ෇༩͢Δ͜ͱͰϑΝΠϧΞ Ϋηε΍ϓϩηεͷىಈͳͲΛ੍ޚͯ͠ηΩϡΞͳ࣮ߦΛՄೳʹ͢Δ • ·ͩͲ͏͍͏ܗࣜʹ͢Δ͔΋ٞ࿦த •

    Denoͷ `—allow-…`ͷΑ͏ʹڐՄܗࣜʹ͢Δ͔ɺ 
 `—deny-…`ͷΑ͏ʹېࢭܗࣜʹ͢Δ͔΋ܾ·͍ͬͯͳ͍
  30. Next 10 years

  31. next-10 • Node.js ͷࠓޙ10೥Ͳ͏͢Δ͔ͷٞ࿦͕͞Ε͍ͯΔ • https://github.com/nodejs/next-10 • ϦϙδτϦ಺ͷ TECHNICAL_PRIORITY_WORKING_SUMMARY.mdʹ 


    ༏ઌ౓ͷߴ͍ػೳͷҰཡͱؔ࿈ϦϯΫ͕ܝࡌ͞Ε͍ͯΔ • nodejs/node ϦϙδτϦ಺ͷ doc/contributing/technical-priorities.md ʹ ༏ઌ౓ͷߴ͍ػೳͷ֓ཁ͕ܝࡌ͞Ε͍ͯΔ • ࣮૷͞Ε࢝Ί͍ͯΔ΋ͷ΋͋Δ͕ٞ࿦தͷ΋ͷ΋ଟ͍
  32. https://github.com/nodejs/node/blob/HEAD/doc/contributing/technical-priorities.md next-10Ͱ༏ઌతͳػೳͷ֓ཁ͕ه͞Ε͍ͯΔ

  33. 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
  34. 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) ʹৄࡉ͕ܝࡌ͞Ε͍ͯΔ
  35. Support for features from the latest ECMAScript spec • ࠷৽ͷECMAScriptͷ࢓༷Λαϙʔτ͍ͨ͠

    • ESͷ࢓༷௥ਵ͸V8(JSΤϯδϯ)ͷߋ৽ʹΑͬͯߦΘΕ͍ͯΔ • ݱࡏ͸V8ͷߋ৽͕ϝδϟʔόʔδϣϯͷͱ͖ͷΈߦΘΕ͍ͯΔ • ·ͩํ๏͸ະఆ͕ͩ࢓༷௥ਵͷͨΊʹݱࡏͷํ๏Λม͑Δඞཁ͕͋Δ
  36. ·ͱΊ • Node.js v18ͱv19ʹ͸fetch΍Web Streams APIͳͲWebޓ׵ͳػೳ ͕ϑϥάͳ͠Ͱ࢖͑ͨΓstableʹͳͬͨ • ςετϥϯφʔ΍watchϞʔυͳͲ։ൃମݧΛ޲্ͤ͞ΔͨΊͷػೳ ΋௥Ճ͞Εͨ

    • Node.jsͷ࣍ͷ10೥ʹ޲͚ͯٞ࿦͕։࢝͞Ε͍ͯΔ • ༏ઌ౓͕ߴ͍ػೳ͔Β࣮૷΍ٞ࿦͕࢝·͍ͬͯΔ
  37. https://jsconf.jp JSConf JPͰ΋Node.jsʹ͍ͭͯͷτʔΫ͕͋Γ·͢ʂ

  38. Thanks