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. HTTP requestTimeout()ͷσϑΥϧτ஋ͷมߋ • server.requetTimeoutͷλΠϜΞ΢τ࣌ؒͷσϑΥϧτ஋͕ 
 0 ͔Β 300000ϛϦඵ (5෼) ʹͳΓ·ͨ͠ɻ

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

    • Node.jsͷݹ͍Streamͱ͸ޓ׵ੑͳ͠ • Node.js v18͔Βϑϥάͳ͠Ͱ 
 ࢖༻Մೳʹͳ͕ͬͨ·ͩExperimental
  3. 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) => { // ... })
  4. --experimental-speci fi er-resolution ϑϥάͷ࡟আ • import ‘./foo’; ͱॻ͖͍ͨ৔߹ɺ—experimental-speci fi er-

    resolution=nodeϑϥάΛ͚࣮ͭͯߦ͢Ε͹ิ׬ͯ͘͠Ε͍ͯͨ • ESM͸࢓্༷ɺ֦ுࢠͷলུ͕ڐ͞Ε͍ͯͳ͍ • import xxx from ‘./foo’ ͱ͸ॻ͚ͳ͍ɻ’./foo.js’ͱ͠ͳ͚Ε͹ͳΒͳ͍ • ୅ସखஈˠCustom LoaderΛ࡞Δ •
  5. Web Crypto API ͕ stable ʹ • ϒϥ΢β(Web)ͷ Crypto API

    ͱΠϯ λʔϑΣʔεޓ׵͕͋Δ • Node.jsͷݹ͍Crypto APIͱޓ׵͸ͳ͍ • ҉߸Խ΍෮߸Λ͢Δ͜ͱ͕Ͱ͖ΔAPI
  6. 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); });
  7. 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& ·ͱΊͯ̍ͭͷ 
 ࣮ߦϑΝΠϧ΁
  8. next-10 • Node.js ͷࠓޙ10೥Ͳ͏͢Δ͔ͷٞ࿦͕͞Ε͍ͯΔ • https://github.com/nodejs/next-10 • ϦϙδτϦ಺ͷ TECHNICAL_PRIORITY_WORKING_SUMMARY.mdʹ 


    ༏ઌ౓ͷߴ͍ػೳͷҰཡͱؔ࿈ϦϯΫ͕ܝࡌ͞Ε͍ͯΔ • nodejs/node ϦϙδτϦ಺ͷ doc/contributing/technical-priorities.md ʹ ༏ઌ౓ͷߴ͍ػೳͷ֓ཁ͕ܝࡌ͞Ε͍ͯΔ • ࣮૷͞Ε࢝Ί͍ͯΔ΋ͷ΋͋Δ͕ٞ࿦தͷ΋ͷ΋ଟ͍
  9. 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
  10. 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) ʹৄࡉ͕ܝࡌ͞Ε͍ͯΔ
  11. Support for features from the latest ECMAScript spec • ࠷৽ͷECMAScriptͷ࢓༷Λαϙʔτ͍ͨ͠

    • ESͷ࢓༷௥ਵ͸V8(JSΤϯδϯ)ͷߋ৽ʹΑͬͯߦΘΕ͍ͯΔ • ݱࡏ͸V8ͷߋ৽͕ϝδϟʔόʔδϣϯͷͱ͖ͷΈߦΘΕ͍ͯΔ • ·ͩํ๏͸ະఆ͕ͩ࢓༷௥ਵͷͨΊʹݱࡏͷํ๏Λม͑Δඞཁ͕͋Δ