Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
春からはじめる新しいNode.js / start new Node.js in spring
Search
Masashi Hirano
April 20, 2018
Programming
2
980
春からはじめる新しいNode.js / start new Node.js in spring
関西Node学園 梅田キャンパス 1時限目
https://nodejs.connpass.com/event/82614/
でNode.js v10やEcmaScriptの新機能の話をしました。
Masashi Hirano
April 20, 2018
Tweet
Share
More Decks by Masashi Hirano
See All by Masashi Hirano
You may not need XXX in Node.js
masashi
5
1.2k
OSSとコミュニティを支える
masashi
1
1.1k
英語ができなかった自分達が、グローバルチーム立ち上げに挑戦!?
masashi
1
3.1k
フロントエンド開発のためのセキュリティ入門について
masashi
1
460
フロントエンド開発のためのセキュリティ入門
masashi
49
17k
Node.jsの2022年と未来 / Node.js in 2022 and Future
masashi
1
1k
Corepack ~Node.jsに追加されたパッケージマネージャーマネージャー~ / #tng37
masashi
3
12k
Node.js + Web Compatibility
masashi
2
600
サイボウズが行うフロントエンドの品質保証 / Frontend Quality Assurance at Cybozu
masashi
10
2.9k
Other Decks in Programming
See All in Programming
ゆるやかにgolangci-lintのルールを強くする / Kyoto.go #56
utgwkk
1
360
menu基盤チームによるGoogle Cloudの活用事例~Application Integration, Cloud Tasks編~
yoshifumi_ishikura
0
110
talk-with-local-llm-with-web-streams-api
kbaba1001
0
170
ソフトウェアの振る舞いに着目し 複雑な要件の開発に立ち向かう
rickyban
0
890
rails stats で紐解く ANDPAD のイマを支える技術たち
andpad
1
290
103 Early Hints
sugi_0000
1
220
MCP with Cloudflare Workers
yusukebe
2
220
The Efficiency Paradox and How to Save Yourself and the World
hollycummins
1
440
As an Engineers, let's build the CRM system via LINE Official Account 2.0
clonn
1
670
DevFest Tokyo 2025 - Flutter のアプリアーキテクチャ現在地点
wasabeef
5
900
創造的活動から切り拓く新たなキャリア 好きから始めてみる夜勤オペレーターからSREへの転身
yjszk
1
130
バグを見つけた?それAppleに直してもらおう!
uetyo
0
170
Featured
See All Featured
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
Visualization
eitanlees
146
15k
How to train your dragon (web standard)
notwaldorf
88
5.7k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
5
440
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
[RailsConf 2023] Rails as a piece of cake
palkan
53
5k
The Pragmatic Product Professional
lauravandoore
32
6.3k
Docker and Python
trallard
41
3.1k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
170
Music & Morning Musume
bryan
46
6.2k
Statistics for Hackers
jakevdp
796
220k
Transcript
य़͔Β͡ΊΔ ৽͍͠Node.js ؔNodeֶԂ #1 ฏ ণ࢜ / @shisama
{ "about": { "name": "Masashi Hirano", "works": "Weblio, Inc.", "twitter":
"@shisama_", "github": "shisama" } }
Agenda • ݱࡏͷNode.jsΛ෮श • ৽͍͠Node.jsΛ༧श • ৽͍͠Node.jsΛ࣮श
ରͱ͢Δਓ • Node.jsΛͬͨ͜ͱ͋Δਓ • Node.jsͬͯΔ͚Ͳɺ࠷৽ใΛΓ͍ͨਓ • ݹ͍όʔδϣϯͷNode.jsͬͯΔਓ
ࠓ͞ͳ͍͜ͱ • Node.jsͱ • ϑϩϯτΤϯυ(jQuery,React,Angular,Vue…) • ػೳ༷ͷͯ͢ʢ࣌ؒత੍ʣ
Goal • Node.jsͷ࠷৽ใΛΔ • ݹ͍ڥΛΞοϓσʔτ͢Δ • ৽͍͠Node.jsͷػೳΛͬͯΈΔ
·ͣࠓճ͢༰ʹؔ͢Δ ༻ޠΛͬ͘͟Γ෮श
V8 engine • Google͕։ൃ͢ΔJavaScriptΤϯδϯ • ChromeͱNode.jsͰΘΕ͍ͯΔ • ࣮ߦ͕͍
npm • Node Package Manager • ϥΠϒϥϦཧ • λεΫ࣮ߦ
V8ɺnpmͷόʔδϣϯใ https://nodejs.org/en/download/releases/
EcmaScript • JavaScriptͷ༷ • ҰൠతʹEcmaScriptECMA-262Λࢦ͢ • TC39ͱ͍͏ҕһձ͕༷ࡦఆΛ͍ͯ͠Δ • Living Standard
• ৗʹ༷͕Ξοϓσʔτ͞ΕΔ
EcmaScript • 2ϲ݄ʹ1ճϛʔςΟϯά͕ߦΘΕ͍ͯΔ • ֤ػೳͷεςʔδߋ৽ͳͲ͕ٞ͞ΕΔ • stage-4ʹͳͬͨͷ͕1ʹ1ճEcmaScript ͷ༷ͱͯ͠ϦϦʔε͞ΕΔ(ES201X)
EcmaScript • ༷ࡦఆ·Ͱʹstage0ʙstage4·Ͱͷஈ֊͕ଘࡏ͢Δ • 0 Strawman - ΞΠσΞ • 1
Proposal - ఏҊ • 2 Draft - υϥϑτ • 3 Candidate- ༷ॻͱಉ͡ܗࣜ • 4 Finished - ࡦఆྃ
EcmaScript https://azu.github.io/slide-what-is-ecmascript/slide/ B[V͞Μͷʰ&$."4DSJQUͱԿ͔ʁʱ͕ Θ͔Γ͍͢ͷͰಡΜͰΈͯ΄͍͠
&DNB4DSJQUͷ࠷৽ใ5$ͷ ϦϙδτϦʹ͋Γ·͢ʂ
ݱࡏͷNode.jsΛ෮श
Release Schedule • github.com/nodejs/Releaseʹࡌ͍ͬͯΔ • ʹҰճϝδϟʔϦϦʔε͕ߦΘΕΔ
https://github.com/nodejs/Release
https://github.com/nodejs/Release
Active • LTS (Long Term Support) • 18ϲ݄ؒαϙʔτ͕ߦΘΕΔ • ຖ10݄͔ΒLTS
ActiveʹͳΔ • όʔδϣϯ൪߸͕ۮ
https://github.com/nodejs/Release
Current • ࠷৽ͷϦϦʔε൛ • ϝδϟʔόʔδϣϯ͕حˠ10݄ʹϦϦʔε • ϝδϟʔόʔδϣϯ͕ۮˠ4݄ʹϦϦʔε
https://github.com/nodejs/Release
Maintenance • LTSCurrentظؒऴྃޙͷϝϯςφϯεظؒ • LTS12ϲ݄ؒαϙʔτ • όάɺ੬ऑੑɺυΩϡϝϯτͳͲ͕ϝϯς͞ ΕΔ
https://github.com/nodejs/Release ݱࡏαϙʔτதͷόʔδϣϯʁ
Node 4.x • V8Τϯδϯ4.5 • ES2015ͷػೳͷଟ͕͑͘ΔΑ͏ʹ • 2018/04/30ʹϝϯςφϯεऴྃ༧ఆ • αϙʔτࢭ·ΔͷͰΞοϓσʔτඞਢ
Node 6.x • V8Τϯδϯ5.1 • ProxyσϑΥϧτҾ͕͑ΔΑ͏ʹ • 2018/04/30͔ΒLTSͰͳ͘ͳΔ༧ఆ • ϝϯςφϯε͞ΕΔ͚Ͳདྷ4݄ʹαϙʔτ
ऴྃ༧ఆ
Node 8.x • ݱࡏͷLTS • V8Τϯδϯ6.1 • async / awaitΛαϙʔτ͢Δ࠷ॳͷLTS
• util.promisify, inspectorͳͲ͕Ճ͞Εͨ
Node 8.x • npm@5 • package-lock.json • 8.5͔Βϑϥά͖ͰES Modules͑Δ •
import / export syntax • AWS LambdaͰ࠷ۙΑ͏͘v8͕͑ΔΑ͏ʹ
Node 8.x • 2019/04͔ΒLTSͰͳ͘ͳΔ • 2019/12ʹϝϯςφϯεऴྃ • ࠓ͏ͳΒ͜ͷόʔδϣϯ͕ແ
Node 9.x • ݱࡏͷCurrent • V8Τϯδϯ6.2 • HTTP2͕ϑϥάͳ͠Ͱ͑Δ • 2018/06/30Ͱϝϯςφϯεऴྃ༧ఆ
͜͜·Ͱͷ͓͞Β͍ • 4.xͬͯΔਓࠓ݄தʹΞοϓσʔτ • 6.xͬͯΔਓ̍ҎʹΞοϓσʔτ • 8.xͬͯΔਓ·ͩ̍Ҏ্େৎ • 9.xͬͯΔਓ݄̒·ͰʹΞοϓσʔτ
͜͜·Ͱͷ͓͞Β͍ • 4.xͬͯΔਓࠓ݄தʹΞοϓσʔτ • 6.xͬͯΔਓ̍ҎʹΞοϓσʔτ • 8.xͬͯΔਓ·ͩ̍Ҏ্େৎ • 9.xͬͯΔਓ݄̒·ͰʹΞοϓσʔτ ࠓ͕Ξοϓσʔτ͢Δͱ͖Ͱ͢Αʂʂ
৽͍͠Node.jsΛ༧श
https://github.com/nodejs/Release
None
Node.js 10.0 • 2018/04/24ʹϦϦʔε༧ఆ • ࣍ͷLTS • V8Τϯδϯ6.6 • npm@6(ϦϦʔε࣌ʹೖΔ͔ະఆ)
V8 Engine • ݱࡏͷmasterʹೖͬͯΔͷ6.6 • 6.7ʹͯ͠΄͍͠ཁ͋Δ
WWFSTJPOIʹఆٛ͞Ε͍ͯΔ https://github.com/nodejs/node/blob/master/deps/ v8/include/v8-version.h ࠷৽ͷNode.jsͷV8ʁ
V8 engine • Node 9.x(V8 6.2) => Node 10.0(V8 6.6)
• EcmaScript৽ػೳͷՃ(ޙड़) • ࣮ߦͷվળ • asyncͷύϑΥʔϚϯεվળ
https://github.com/nodejs/node/pull/19091 V8 6.7 7ʹTUBCMFʹͳΔ͚Ͳɺ ͦΕͰ͗͢Δ /PEF݄ޙʹϦϦʔε͍ͨ͠
V8 6.7 • Chrome 67 • BigInt(64bitܕ)ͳͲEcmaScript৽ػೳͷ Ճ • Node
v10Ͱϑϥά͖Ͱ͑Δͷ͋ Δ
npm@6 https://github.com/npm/npm/releases/tag/v6.0.0-next.0 มߋখ͞Ίɻ/PEF͕ϦϦʔε͞Ε Δ·Ͱখ͍͞มߋ͔͠͠ͳ͍༧ఆ
npm@6 https://github.com/npm/npm/releases/tag/v6.0.0-next.0 ࠓޙʹେ͖ͳมߋΛೖΕΔ ༧ఆɻOQN!ʹʂ
npm@6 • Node 10.0ʹ͚ͯখ͞ͳมߋ͋Δ • Node 4.xͱNode 7.xͷαϙʔτऴྃ • npm
ci && npm tͳnpm cit͕Ճ • npm install͢Δͱ͖ʹdeprecateͷόʔδϣϯ ΛճආͳͲ
deprecateͷόʔδϣϯΛճආ $ npm install example@~1.1.0 // 1.1.2 // 1.1.3 (deprecated)
// 1.2.0 (latest) ͕Yͷ࠷৽͕ͩɺEFQSFDBUFʹͳͬ ͍ͯΔͨΊΠϯετʔϧ͞Εͳ͍
EcmaScript৽ػೳ • ଟ͘ͷػೳ͕Ճ͞Εͨ • ES Modules·ͩϑϥά͚ͳ͍ͱ͑ͳ͍
Node.js v10ʹՃ͞ΕΔ EcmaScript৽ػೳ • Dynamic import • Async Iteration •
Promise.prototype.finally • RegExp New Features • Intl.NumberFormat.formatToParts • Function.prototype.toString() • Optional catch binding • String.prototype.trimStart • String.prototype.trimEnd
Dynamic Import (async() => { let count = 0; let
id = setInterval(async() => { const i = Math.floor(Math.random() * 3) + 1; const module = await import(`./hello${i}.mjs`); module.hello(); count++; if (count === 10) { clearInterval(id); } }, 1000); })(); ಈతʹϞδϡʔϧΛJNQPSUՄ ೳʹ
Async Iteration async function* gen() { while (true) { const
res = await axios.get(‘https:// hogehoge.com'); const data = await res.data; yield data; } } (async() => { for await (const data of gen()) { console.log(data); } })(); 1SPNJTFͳྻΛGPSBXBJU PGͰඇಉظϧʔϓ͕Մೳʹ
Promise.prototype.finally Promise.resolve(“then”) .then(val => { console.log(val); throw new Error(“catch") }).catch(err
=> { console.log(err.message) }).finally(() => { console.log(“finally") }); pOBMMZ ͕Ճ
RegExp New Features const result = '123$456 $789 $ 000'.match(/(?<=\
$)\d+/g); console.log(result); // ['456', '789'] ਖ਼نදݱͷޙಡΈ͕Մೳɻ ଞʹ υοτ ͕վߦจࣈʹϚον͢ ΔΑ͏ʹͳΔTϑϥάͳͲ
Intl.NumberFormat.formatTo Parts const num = 1000; const formatter = new
Intl.NumberFormat('ja-JP', { style: 'currency', currency: 'JPY' }); const yen = formatter.formatToParts(num).map(({type, value}) => { switch (type) { case 'currency': return "<strong>" + value + "</ strong>"; default: return value; } }).reduce((string, part) => {return string + part}); console.log(yen); // => "<strong>¥</strong>1,000" ͷΧελϜϑΥʔϚοτ ͕Մೳʹ
Function.prototype.toString function /* a comment */ foo () {} foo.toString();
// → 'function /* comment */ foo () {}' UP4USJOH ͷ༷มߋ
Optional catch binding try { const a = 1; a
= 2; } catch { console.error("catch"); } DBUDIͷҾͳ͠ͰՄೳʹ
String.prototype.trim{Start|End} const value = " has spaces "; console.log(`‘${value}'`); //
=> ‘ has spaces ‘ console.log(`‘${value.trimStart()}'`); // => ‘has spaces ‘ console.log(`trimEnd: '${value.trimEnd()}'`); // => ‘ has spaces‘ จࣈྻͷલޙͷεϖʔεΛআ ڈ
http://node.green/ OPEFHSFFOͱ͍͏αΠτʹ /PEFKTͷόʔδϣϯ͝ͱʹ &4ͷͲͷػೳ͕͑Δ͔ࡌ͍ͬͯΔ
ͦͷଞؾʹͳΔՃػೳ • fs͕PromiseϕʔεͰಈ͔ͤΔΑ͏ʹͳͬͨ • const data = await fs.readFile(‘./ something’,
‘utf-8’); • util.types.isPromiseͱ͔isDateͰܕఆ ͳͲ
Wʹ͍ͭͯͬͱৄ͍͠Λฉ ͖͍ͨਓདྷि౦ژʂ
৽͍͠Node.jsΛ࣮श
࠷৽ͷNode.jsΛ͏
https://github.com/nodejs/Release
master • ࠷৽ͷιʔείʔυ • ຖେྔʹίϛοτ͞Ε͍ͯΔ • ࠓϏϧυ͢ΔͱNode 10.0.0-preʹͳΔ
Node.jsΛϏϧυ https://github.com/nodejs/node/blob/master/BUILDING.md #6*-%*/(NEΛݟΕ֤04͚ͷखॱ͕ॻ ͔Ε͍ͯΔɻ Ϗϧυ࣌ؒͦΜͳʹ͔͔Βͳ͍
Node.jsΛϏϧυ $ ./configure $ make -j4 Ϗϧυதɾɾɾ $ ./node -v
> v10.0.0-pre ͜Ε͚ͩ
Ϗϧυͨ͠Node.jsΛ͏ • ৽ػೳΛࢼͯ͠ΈΔ ➡ ࠓհͨ͠ES৽ػೳಈ͘ʂʂ • Nodeຊମͷ࣮Λมߋͯ͠ಈ͔ͯ͠ΈΔ
͞Βʹ৽͍͠ػೳΛࢼ͢ • Node.jsʹ࣮ݧతʹ࣮͞Ε͍ͯΔػೳ͕͋ Δ • ϑϥάΛ͚ͭΔ͜ͱͰ͑Δ • ES Modules·࣮ͩݧతͳػೳ
ES Modules $ node —experimental-modules index.mjs FYQFSJNFOUBMNPEVMFTϑϥάΛ͏ɻ ֦ுࢠNKT
harmony • --harmonyϑϥάΛ࣮͑ݧతͳػೳ͕͑ ΔΑ͏ʹͳΔ • Node.jsʹ࣮͞Ε͍ͯΔEcmaScriptͷػೳʹ ΑͬͯϑϥάมΘΔ • EcmaScriptͷػೳ̏ͭʹ͚ΒΕΔ
EcmaScriptͷػೳ • shipping: ϦϦʔεࡁ • ϑϥάͳ͠Ͱ࣮ߦՄೳ • staged: ΄΅͕ͩɺ҆ఆ͍ͯ͠ΔͱΈͳ͞Εͳ͍ •
--harmonyϑϥάͰ࣮ߦՄೳ • in progress: ։ൃத • --harmony-class-fieldsͷΑ͏ʹݸʑʹ༻ҙ͞Εͨ harmonyϑϥά
harmony ֬ೝํ๏ $ node —v8-options | grep harmony --es_staging (enable
test-worthyɾɾɾ --harmony (enable all completedɾɾɾ --harmony_shipping (enable allɾɾɾ --harmony_array_prototype_values (ɾɾ --harmony_function_sent (enableɾɾɾ ͲΜͳIBSNPOZϑϥά͕͋Δ͔W PQUJPOTΛ࣮ߦ͢Ε֬ೝͰ͖Δ
harmony ྫ $ node —harmony-bigint > typeof 123n ‘bigint’ >
123n + 1n 124n IBSNPOZϑϥάΛ͚ͭΔ͜ͱͰ#JH*OU ͑Δ /PEFW
Node.jsʹ࣮͞Ε͍ͯͳ͍ػೳΛ͏ • BabelͰτϥϯεύΠϧ • EcmaScriptશػೳΛΧόʔ͍ͯ͠ΔΘ͚Ͱͳ ͍ • Node.jsͱޓੑ͕ͳ͍SyntaxͰಈ͘ͷͰҙ • import
{readFile} from ‘fs’; ͜ΕNode.jsͰ ErrorʹͳΓ·͢
Ξτϓοτ͢Δ • ৽͍ٕ͠ज़ʹ৮ΕͨΒ͔ͤͬ͘ͳͷͰݟΛ ڞ༗ͯ͠΄͍͠ʂ • ϒϩά • Qiita • ษڧձ
ؔNodeֶԂ ͍ͭͰ͋ͳͨͷొஃΛ ͓͍ͪͯ͠·͢ʂ
·ͱΊ • Node.jsͷαϙʔτظؒΛҙࣝ͠Α͏ʂ • Node.js v10 དྷिϦϦʔεʂ(༧ఆ) • ٕज़Δ͚ͩͰͳ͘ɺͬͯͳΜ΅Ͱ͢ʂ •
ొஃͯ͘͠ΕΔํ͓͍ͪͯ͠·͢ʂʂ
Special Thanks! ओ࠵ऀϝϯόʔ (@sbntaminif, @vanx2, @mdaisuke, @kamiyam,@leichtgewicht), ͘͞ΒΠϯλʔωοτ ༷, εϐʔΧʔͷํʑ(@mochiya98,
@sota1235, @h_michael_z) and ࠓདྷͯ͘Εͨօ༷!! 1ճ։࠵Ͱ͖ͯخ͍͠Ͱ͢ʂ͜Ε͔ΒؔNode ֶԂΛӬ͘ΑΖ͓͘͠ئ͍͍ͨ͠·͢
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠