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

NestJS meetup Tokyo Opening Talk / What is Nest...

NestJS meetup Tokyo Opening Talk / What is NestJS? #nestjs_meetup

2019/11/29 に株式会社エウレカで開催された #nestjs_meetup のスライドです。

potato4d(Takuma HANATANI)

November 29, 2019
Tweet

More Decks by potato4d(Takuma HANATANI)

Other Decks in Programming

Transcript

  1. Takuma HANATANI (@potato4d) • Working at • Senior Front-End Engineer

    at LINE Corp. • CEO at ElevenBack LLC. • Contributions • Vue.js and React.js Japanese document maintainer • Contributed to NestJS for the first time this month • I — • User Interface, Serverless, Cloud Native
  2. Topics 1. ͸͡Ίʹ 2. αʔόʔαΠυ Node.js ͷ՝୊ 3. ͳͥ NestJS

    ͳͷ͔ɻಛ௃ͱັྗ 4. αʔόʔαΠυ Node.js ͷੈքͰ NestJS ʹظ଴͞ΕΔ΋ͷ
  3. Topics 1. ͸͡Ίʹ 2. αʔόʔαΠυ Node.js ͷ՝୊ 3. ͳͥ NestJS

    ͳͷ͔ɻಛ௃ͱັྗ 4. αʔόʔαΠυ Node.js ͷੈքͰ NestJS ʹظ଴͞ΕΔ΋ͷ
  4. Topics 1. ͸͡Ίʹ 2. αʔόʔαΠυ Node.js ͷ՝୊ 3. ͳͥ NestJS

    ͳͷ͔ɻಛ௃ͱັྗ 4. αʔόʔαΠυ Node.js ͷੈքͰ NestJS ʹظ଴͞ΕΔ΋ͷ
  5. Express ࢖͏্Ͱͷ೰Έ • ബ͍ API ͷͭ΋ΓͰ࡞ͬͨ Req/Res Object ʹґଘͨ͠ີ݁߹ͳίʔυ •

    ୭΋࢖ͬͯͳ͍ express-generator • Ϧςϥγʔ͕௿͍ͱ console.log ͰϩΪϯάͯͨ͠Γ͢Δ • 100ਓډͨΒ100ਓҧ͏ΞʔΩςΫνϟʹͳΔࣗ༝౓ • ߴ೉қ౓Խ͢Δ։ൃϧʔϧɾΞʔΩςΫνϟͷ౷Ұ ϚΠΫϩϑϨʔϜϫʔΫʹඞਢͳઃܭ੹೚Λ୭΋ͱΕͣഁ୼͢Δ։ൃମ੍ ☠
  6. ͦ΋ͦ΋ͷؒҧ͍ • Express ͸ศརͳٕज़͕ͩɺͦΕ͚ͩΛ࢖͍ͬͯΕ͹ྑ͍Θ͚Ͱ͸ͳ͍ • ബ͍ͨΊखܰʹ࢖͑Δ͕ɺബ͍͔Βͱ͍ͬͯࡶͰྑ͍Θ͚Ͱ͸ͳ͍ • ബ͍(Less opinionated)ٕज़ʹ͸ബ͍͚ͩͷ੹೚͕൐͏ •

    ϑϨʔϜϫʔΫͷࢥ૝ʹ৐Βͳ͍ͳΒɺࣗ਎͕ࢥ૝Λ࣋ͭ΂͖Ͱ͋Δ • ߟ͑ͳͯ͘ྑ͍ͷͰ͸ͳ͘ɺ౰ࣄऀͱͯ͠ߟ͑ɺ఻͑Δඞཁ͕͋Δ • ࢥߟͱܒ໤ʹ੹೚Λ޿࣋ͯ͘ͳ͍৔߹ɺڱΊΔ͜ͱ͕ॏཁ • աڈͷϑϧελοΫϑϨʔϜϫʔΫ͸͜ΕʹΑͬͯࢥߟΛ࠷খԽͨ͠ • ܕʹ͸·ͬͨ։ൃͷ՝୊΋͋Γɺബ͍΋ͷ͕ٻΊΒΕΔ͜ͱ΋͋ͬͨ
  7. Topics 1. ͸͡Ίʹ 2. αʔόʔαΠυ Node.js ͷ՝୊ 3. ͳͥ NestJS

    ͳͷ͔ɻಛ௃ͱັྗ 4. αʔόʔαΠυ Node.js ͷੈքͰ NestJS ʹظ଴͞ΕΔ΋ͷ
  8. Dependency Injection • ΦϒδΣΫτಉ࢜(Ϋϥεಉ࢜)ͷґଘΛ֎෦͔Βઃఆ͢Δ͜ͱ • Dependency(ґଘΦϒδΣΫτ)ͷInjection(஫ೖ) • ΦϒδΣΫτಉ࢜ͷґଘΛ಺෦Ͱղܾ͠ͳ͍͜ͱʹΑͬͯɺςελϒϧ͔ͭ ൚༻ੑͷߴ͍ίʔυΛॻͨ͘ΊͷςΫχοΫ •

    DAO ͕ؔΘΔΦϒδΣΫτςετͮ͠Β͍໰୊ • ֎෦ API ͕ؔΘΔΦϒδΣΫτςετͮ͠Β͍໰୊ • ͦͯ͠ DI Λ͏·͘औΓѻ͏࢓૊ΈΛఏڙ͞Ε͍ͯΔ (DIίϯςφ) NestJSΛ࢖͏͜ͱͰʮࣗવͱґଘؔ܎Λҙࣝͨ͠ίʔυ͕࡞ΒΕΔʯΑ͏ʹ
  9. Opinionated Architecture • DI Λલఏͱͨ͠ Service ͱͦΕΛར༻͢Δ Provider / Module

    • ൚༻తͳ Service ͱɺΞϓϦέʔγϣϯ޲͚ͷೖΓޱͷ Module • ࣗવͱϨΠϠͱϢʔεέʔεʹ͍ͭͯߟྀ͞ΕΔΑ͏ʹ • ؔ৺ྖҬʹ͍ͭͯ͸ըҰతͳղܾํ๏Λఏڙ • HTTPϨεϙϯεɾೝূɾόϦσʔλɾྫ֎ϕʔεͷҟৗܥ؅ཧɾϩά • ҰํͰଞͷϑϨʔϜϫʔΫʹ͸͋Δ͕ຊ࣭తͰͳ͍΋ͷ͸ແؔ৺ • ίΞʹ͸ RDB ΍ NoSQL ΁ͷػೳ͸ଘࡏ͠ͳ͍(௥Ճ͸Մೳ) ʮඞཁͳ΋ͷΛબ୒͢Δ͚ͩͰɺࣗવͱNestΒ͘͠ͳΔʯར఺͕͋Δ
  10. Progressive Ecosystem • NestJS ͸ίΞʹ͸ͳ͍͕ΦϑΟγϟϧͷύοέʔδ͕େྔʹ͋Δ • σʔλετΞ: TypeORM / Sequalize

    / Mongoose • IDL / Server: GraphQL / gRPC • For starter: Nest CLI • Utilities: Swagger(Open API) / Compodoc / • ։ൃऀ͕ NestJS ʹίΞҎ֎ΛͲ͜·ͰٻΊΔ͔͸ఆٛͰ͖Δ • ϑϧελοΫͰ͸ͳ͘ɺελʔτ࣌ʹղܾ͞Ε͍ͯΔ՝୊͕ଟ͍͚ͩ جຊతͳΞʔΩςΫνϟ͕९क͞ΕͨதͰɺ࠷దͳπʔϧΛ૊Έସ͑ΒΕΔ
  11. Topics 1. ͸͡Ίʹ 2. αʔόʔαΠυ Node.js ͷ՝୊ 3. ͳͥ NestJS

    ͳͷ͔ɻಛ௃ͱັྗ 4. αʔόʔαΠυ Node.js ͷੈքͰ NestJS ʹظ଴͞ΕΔ΋ͷ
  12. αʔόʔαΠυ Node ͕ඞཁͳঢ়گʹ͍ͭͯ • ϓϥοτϑΥʔϜͷ໰୊ • Cloud Native ready ͳ૊৫Ͱ͸ͳ͘

    FaaS ͕ར༻Ͱ͖ͳ͍ • ্ཱ͕ͪΓ͕ϔϏʔͳ΋ͷͷಈ࡞Λཁٻ͞ΕΔ • ։ൃϝϯόʔͷ՝୊ • JavaScript(TypeScript) ͕ୈҰݴޠͷϝϯόʔ͕த৺ • ͍ΘΏΔόοΫΤϯυͷઃܭʹ׳Ε͍ͯΔਓ͕͍Δ͔΋Θ͔Βͳ͍ • ٕज़ؒͷࠩҟΛٵऩ͍ͨ͠ • BFF ͰϑϩϯτΤϯυͱ͸ JSON ͰɺMicroServices ͱ͸ gRPC Ͱ
  13. NestJS ͕͏·͘ڹ͘ϙΠϯτʹ͍ͭͯ • Opinionated ͳ Architecture ʹΑͬͯΈΜͳͰಉ͡౔୆ʹཱͯΔ • ໪࿦ NestJS

    ʹ͍ͭͯͷ஌͕ࣝ͋Δલఏ • ࠷ߴͷઃܭʹ͸ͳΒͳ͍͔΋͠Εͳ͍͕ɺ੺఺ʹͳΔ͜ͱΛ๷͛Δ • جຊ͸ʮWebʯʹؔ͢ΔྖҬʹͷΈؔ৺Λ࣋ͭ • DAO ΍ ORM ͕ίΞ͔Β֎Ε͍ͯΔͨΊɺݎ࿚ͳ͕Βٕज़Λബ͘ར༻͢ Δ͜ͱ͕Մೳ • ಛʹ BFF ͳͲόϦσʔλʔɾೝূج൫͕͔ͬ͠Γͯ͠ཉ͍͠Έ͍ͨͳ৔ ߹͸͕͜͜ޮ͍ͯ͘Δ
  14. NestJS ΛΦϓγϣϯͷͻͱͭͱͯ͠஌Δ • NestJS ͕͍ͭͰ΋༗ޮͳΘ͚Ͱ͸ͳ͍ • 1ΤϯυϙΠϯτͷ؆୯ͳαϯϓϧʹ NestJS ͸ඞཁͳ͍ •

    ΋ͬͱϢʔεέʔεʹԊͬͨઃܭΛΞʔΩςΫτ͕͢Δ΂͖͔΋͠Εͳ͍ • Ͳ͏࢖͑Δͷ͔ɺ͋Δ͍͸࢖͑ͳ͍ͷ͔Λ஌͓ͬͯ͘͜ͱ͕େ੾ • ͦ΋ͦ΋ NestJS ͕Ͳ͏͍͏ػೳΛ༗͍ͯ͠Δͷ͔ • NestJS ͷΧόʔൣғ͸Ͳ͜·ͰͰɺͲͷΑ͏ʹར༻͞Ε͍ͯΔͷ͔ • Ͳ͏͍ͬͨ࣌ʹ NestJS ͕໾ཱͬͨͷ͔