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

JavaScript Bootcamp 2018

JavaScript Bootcamp 2018

2018年4~5月開催「ブートキャンプ特別講座」の資料になります。

Recruit Technologies

July 19, 2018
Tweet

More Decks by Recruit Technologies

Other Decks in Technology

Transcript

  1. JavaScript Bootcamp • ࠓ೔Ͱ JavaScript Λ࢖͍౗͢ • JavaScript Λ஌Δ •

    JavaScript ͰΫϥΠΞϯτΛ࡞Δ • JavaScript ͰαʔόΛ࡞Δ
  2. ࿩ͷલʹ • ϦΫϧʔτςΫϊϩδʔζͷ "ϑϩϯτΤϯυΤϯ δχΞ" ͷఆٛ͸޿ͯ͘ਂ͍ • HTML/CSS/JSΛۦ࢖ͯ͠ΫϥΠΞϯτΛ࡞Δ *͚ͩ Ͱ͸ͳ͍*

    • ωοτϫʔΫͷ஌ࣝ΍αʔόͷجૅ஌ࣝ΋༗͢Δ্ ʹͦΕΒΛ౿·͑ͯαΠτશମͷϢʔβϏϦςΟɾ ύϑΥʔϚϯεΛ্͛Δਓ
  3. JavaScriptΛͱΓ͋͑ͣ࢖ͬͯ ΈΔɻ // ͜͜Ͱ Node.js ͕ೖͬͯΔਓ͸ terminal Λىಈͯ͠ԼهͷίϚϯυΛ࣮ߦ͍ͯͩ͘͠͞ɻ $ node

    -v v9.11.1 REPLΛىಈ͠·͠ΐ͏ $ node > // ͜͜Ͱ΋͏ JavaScript ͕ಈ͖·͢ɺ৭ʑ΍ͬͯΈ·͠ΐ͏ɻ > 1 + 1; 2 > var test = "abc"; test > function test() { ... var num = 2; ... return num; ... } undefined > test(); 2
  4. JavaScriptΛͱΓ͋͑ͣ࢖ͬͯ ΈΔɻ • ΋͏গ͠ڽͬͨ͜ͱΛͯ͠Έ·͠ΐ͏ // ϑΝΠϧͷதͰɺ࣍ͷ഑ྻΛද͢ɺม਺ pets Λఆٛ͠·͠ΐ͏ɻ const pets

    = ['cat', 'dog', 'rat']; // forϧʔϓΛ࡞ͬͯɺ഑ྻ಺ͷ֤จࣈྻ͕ෳ਺ܗʹͳΔΑ͏ʹมߋ͠·͢ɻ // forϧʔϓͷத͸࣍ͷΑ͏ʹͳΔͰ͠ΐ͏... pets[i] = pets[i] + 's'; forϧʔϓ͕ऴΘͬͨΒɺ console.log() Λ࢖ͬͯ഑ྻ pets Λλʔϛφϧʹදࣔ͠·͠ΐ͏ɻ
  5. JavaScriptΛͱΓ͋͑ͣ࢖ͬͯ ΈΔɻ • ͔͜͜Β͸ԋश໰୊Ͱ͢ɻ $ npm install @recruit-tech/javascripting -g $

    javascripting ͜ΕΛ࣮ߦ͠·͠ΐ͏ɻ ࣮ߦ͕ऴΘͬͨΒ೔ຊޠઃఆʹ্ͨ͠Ͱ্͔Βղ͍ͯΈ·͠ΐ͏ɺͳ͓ Introduction ͱ for ϧʔϓʹ͍ͭͯ͸طʹ্ͷ໰୊Ͱ΍ͬͯ·͢ͷͰɺҎԼͷ໰୊Λͱ͖·͠ΐ͏ɻ # ਖ਼نදݱΛ࢖͑ɺϧʔΫ # Arrays more # fizzbuzz 1࣌ؒҐͰʂʂʂ
  6. JavaScriptͱ͸ͲΜͳݴޠ͔ • Node.js Ͱ JavaScript Λֶ΂͹ɺϒϥ΢βͰ΋࢖͑Δ΋ͷʹ ͳΔ͔ʁ • YesͰ͋ΓɺNo •

    จ๏͸ֶ΂Δ͠ɺॻ͖ํ΋ֶ΂Δ͕ɺϒϥ΢βͰͦͷ··࢖ ͑Δ΋ͷʹ͸ͳΒͳ͍ɻ • GUIΛ࡞Δͷ͕ϒϥ΢βͷJavaScript • Server, toolΛ࡞Δͷ͕Node.js
  7. جຊจ๏ͱॻ͖ํ • ஋ • ม਺ • ؔ਺ • σʔλܕ •

    Primitive • Object • Ϋϥε • ৚݅෼ذ • ϧʔϓ • ഑ྻͷߴ֊ؔ਺
  8. ஋ console.log Λલʹ࢖͍·͕ͨ͠ɺ͜Ε͸஋ΛධՁͯ͠දࣔ͢Δͷʹ࢖͍·͢ɻ > console.log(1 + 1) 2 > console.log("Hello"

    + "World") HelloWorld `console.log` ͜Ε͸΋ͷ͘͢͝Α͘࢖͏ͷͰʢdebug࣌ʣ֮͑ͯԼ͍͞ɻ஋͕Α͘෼͔Β ͳ͘ͳͬͯ஌Γ͍ͨͳͬͯࢥͬͨΒ console.log Ͱ؆қdebugͯ͠දࣔ͢Δࣄ͕ଟ͍Ͱ͢ɻ
  9. ม਺ ஋Λཧղͨ͠Βɺม਺Λཧղ͠·͠ΐ͏ɻ ม਺͸஋ʹ໊લ෇͚ͯอ࣋͢ΔͨΊʹ࢖͏ `஋ʹ໊લΛ͚ͭΔ࢓૊Έ` Ͱ͢ɻ ม਺ͷ໊લΛ `ม਺໊` ͱݺͼɺม਺͕ࢦࣔ͢͠஋Λ `ม਺஋ ΋͘͠͸ͨͩͷ

    ஋` ͱݺͼ·͢ɻʮ஋ʹ໊લΛ͚ͭΔࣄʯΛม਺એݴɺͱݴ͍·͢ɻ ໊લͷӨڹൣғͷࣄΛʮείʔϓʯͱݴ͍·͢ɻ JavaScript ʹ͸ 3छྨͷม਺એݴͷ࢓૊Έ͕͋Γ·͢ɻ ͓ͳ͡Έͷ var, let, const Ͱ͢ɻͦΕͧΕઆ໌͠·͢ɻ
  10. ม਺ - ม਺એݴ var a = 1; let b =

    2; const c = 3; console.log(a, b, c); جຊతʹ var Ͱ΋ let Ͱ΋ const Ͱ΋ม਺Λએݴ͢Δͱ͍͏ҙຯͰ͸ҰॹͰ͢ɻ ͪͳΈʹͲΕΛҰ൪࢖͏͔ͱ͍͏ͱɺ const > let >>>>>>(ӽ͑ΒΕͳ͍น)>>>>>>> var ͘Β͍ͷॱͰ࢖͍·͢ɻ
  11. ม਺ - ม਺એݴ const Ͱએݴ͢Δͱ࠶୅ೖ͕Ͱ͖ͳ͘ͳΓ·͢ɻ const c = 3; c

    = 4; // TypeError ࠶୅ೖͰ͖ͳ͍ͱਖ਼௚໘౗ͩͳ͍ͬͯ͏ؾ΋͢Δ͔΋͠Ε·ͤΜ͕ɺ࠶୅ೖ͠ͳ͍ͱ͍͏ࣄ ͸ίʔυΛಡΉଆʹऔͬͯΈΔͱɺม਺ͷ஋͕୅ೖ͞ΕͯมԽ͞ΕΔ͜ͱ͕ແ͍ͱ͍͏ࣄΛ ࢦ͢ͷͰಡΉଆ͸͍͘Βָ͔ʹͳΓ·͢ɻ جຊతʹconstͰॻ͍͍ͯΕ͹ɺ൓ରʹ let c = 3; ͱॻ͔Ε͍ͯͨΒʮ͜ͷม਺ c ͸࠶୅ೖ͢Δͧʯͱ͍͏એݴͱ΋औΕ·͢ɺ͜ͷΑ͏ʹ͠ ͯɺ const/letΛ࢖͍෼͚͍ͯ͘ͱྑ͍Ͱ͠ΐ͏ɻ
  12. ม਺ - ม਺એݴ var ͸͍ͭ࢖͏ͷ͔ʁ ͦ͏ࢥͬͨ͋ͳͨɺྑ͍࣭໰Ͱ͢ɻ var ͸جຊతʹ࢖͍·ͤΜɻͨͩ͠ҎԼͷಛఆͷ৚݅Ͱ࢖͏ࣄ͕͋Γ·͢ɻ - const/let

    ͸ ES2015Ҏ߱Ͱ༗ޮͳͨΊɺͦΕҎલͷϒϥ΢β/NodeͰ΋ಈ࡞͢ΔJavaScriptΛ ॻ͖͍ͨ࣌ - γϏΞͳੑೳ͕ٻΊΒΕɺconst/letΑΓ΋ߴ଎Խ͍ͨ࣌͠ ͳΜͰ࢖Θͳ͍ͷ͔ʁ ࣍ͷείʔϓͰղઆ͠·͢ɻ
  13. ม਺ - ม਺είʔϓ JavaScript ͷ const/let ͱ var ͷҰ൪ͷҧ͍͸͜ͷ `είʔϓ`

    Ͱ͢ɻ JavaScript ͷείʔϓ͸جຊతʹ3छྨ͔͋͠Γ·ͤΜɻ - άϩʔόϧείʔϓ (var/let/const) - ϩʔΧϧείʔϓ (var/let/const) - ϒϩοΫείʔϓ (let/const) άϩʔόϧείʔϓ͸Ͳ͔͜ΒͰ΋ม਺͕ಡΊΔɺॴҦάϩʔόϧม਺ͱݺ͹ΕΔม਺ͷҰ൪௕͍ Өڹൣғ͕͋ΔείʔϓͰ͢ɻ ϩʔΧϧείʔϓ͸ؔ਺ͷதͳΒͲ͔͜ΒͰ΋ม਺͕ಡΊΔؔ਺಺ʹͷΈӨڹ͕͋ΔείʔϓͰ͢ɻ ϒϩοΫείʔϓ͸ ϒϨʔε `{}` Ͱғ·ΕͨྖҬͰͷΈಡΊΔҰ൪Өڹ͕গͳ͍είʔϓͰ͢ɻ
  14. ม਺ - ม਺είʔϓ var a = 1; let b =

    2; const c = 3; ͜Ε͸શͯάϩʔόϧείʔϓͰ͢ɻ function foo() { var a = 1; let b = 2; const c = 3; } ͜Ε͸શͯϩʔΧϧείʔϓͰ͢ɻ function bar() { { var a = 1; //͜Ε͚ͩϩʔΧϧείʔϓ let b = 2; // let ͱ const ͸ϒϩοΫείʔϓ const c = 3; } console.log(a) // 1, b ͱ c ͸͔͜͜Β͸ݟΕͳ͍ }
  15. ؔ਺ ॲཧΛ·ͱΊͯ̍ͭͷॲཧʹͯ͠ఆٛ͢Δ͜ͱΛؔ਺ఆٛɺఆٛ͞Εͨؔ਺Λݺͼग़͢͜ͱ Λؔ਺ݺग़͠ɺͱݴ͍·͢ɻ ؔ਺ఆٛ͢Δํ๏͸JavaScript Ͱ͸2௨Γ͋Γ·͢ɻ - จʹΑΔఆٛ function a() {}

    - ࣜʹΑΔఆٛ const a = function() {}; ͲͪΒΛ࢖͏΂͖͔͸ଟগ༳Ε·͢ɻؔ਺ࣜʹΑΔએݴͷ৔߹ɺר্͖͕͛ى͜Βͳ͍ͷͰ constͱ૊Έ߹Θͤͯείʔϓ಺ʹด͡ࠐΊ͍ͨ࣌ʹ࢖͍·͢ɻ (Ϋϩʔδϟͷ࣌ͳͲɻ) ࣜͷ৔߹͸ແ໊ؔ਺Λ࡞ͬͯͦ͜ʹม਺໊ΛΞαΠϯ͢Δࣄ͕ଟ͍Ͱ͢ɻ
  16. Ξϩʔؔ਺ Q1. ໰୊ const A = { foo: () =>

    { console.log(this); } } const B = { foo: function() { console.log(this); } } A.foo() // Կ͕දࣔ͞ΕΔͰ͠ΐ͏͔ B.foo() // Կ͕දࣔ͞ΕΔͰ͠ΐ͏͔
  17. Ξϩʔؔ਺ - Ξϩʔؔ਺ͷ಺෦ʹ͸ `this` ͕ଘࡏ͠ͳ͍ɺؔ਺ఆٛ࣌ʹ `this` ͕੩తʹܾఆ͞ΕΔɻ - ௨ৗͷؔ਺ͷ৔߹͸ `this`

    ͕ؔ਺ݺͼग़࣌͠ʹಈతʹܾఆ͞ΕΔɻ const B = { foo: function() { console.log(this); } } B.foo() // class B const a = B.foo; a() // global object const a = B.foo.bind(B);
  18. ଈ࣌ؔ਺ Α͋͘ΔΠσΟΦϜ: ଈ࣌ؔ਺ɺ͔͠͠΋͏࢖͏͜ͱ͸ͳ͍͔΋ɻ (function() { 
 var a = 1;


    })(); ্ͷؔ਺͸ؔ਺Λఆٛͯ͠௚ޙʹݺͼग़͢ΠσΟΦϜͰ͢ɻ એݴͨ͠௚ޙʹݺͼग़ؔ͢਺ͱͯ͠ɺଈ࣌ؔ਺ͱݺ͹Ε·͢ɻ ͜Ε͸είʔϓΛϩʔΧϧείʔϓʹด͡ࠐΊ͍ͨ࣌ʹ࢖͏ߏจͰ͕͢ɺvarએݴ͔͠Ͱ͖ͳ͔ͬ ͨ࣌ͷΠσΟΦϜͰ͢ɻࠓ͸࢖͍·ͤΜɻ୅ΘΓʹϒϩοΫείʔϓΛ࢖͍·͠ΐ͏ɻ { const a = 1; } ͪ͜Βͷํ͕໌֬Ͱ͢ɻ
  19. σʔλܕ - Primitive جຊతͳܕͰ͋Δ Primitive ܕ͸ String, Boolean ͱ͍ͬͨσʔλܕΛࢦ͍ͯ͠·͢ɻ -

    Booleanܕ : ॴҦ true, false ͕ೖΔܕΛࢦ͍ͯ͠·͢ɻ - Stringܕ: ॴҦ "Node.js" Έ͍ͨͳจࣈྻ͕ೖΔܕΛࢦ͍ͯ͠·͢ɻ - Nullܕ: ஋͕ଘࡏ͠ͳ͍͜ͱΛࣔ͢ܕͰ͢ɻ͍ΘΏΔɹnull - Undefinedܕ: ஋͕ະఆٛͰ͋Δ͜ͱΛࣔ͢ܕͰ͢ɻ͍ΘΏΔ undefined - Numberܕ: 123 Έ͍ͨͳ਺஋͕ೖΔܕΛ͍ࣔͯ͠·͢ɻ͜͜ͰɺJavaScriptͷNumber͸ શͯුಈখ਺Ͱ͢ɻ੔਺ͱখ਺Ͱ෼͔Ε͍ͯͳ͍͜ͱʹ஫ҙɻ - Symbolܕ: ҰҙͰෆมͳσʔλܕɺ͋·Γීஈ͸࢖͏͜ͱ͸ແ͍ͱࢥΘΕΔɻ
  20. σʔλܕ - Primitive typeof true;// => "boolean" typeof 42; //

    => "number" typeof "JavaScript"; // => "string" typeof Symbol("γϯϘϧ");// => "symbol" typeof undefined; // => "undefined" typeof null; // => "object" typeof ["഑ྻ"]; // => "object" typeof { "key": "value" }; // => "object" typeof function() {}; // => "function" ※ typeof null ͕ "object" ͳͷ͸࢓༷όάͰ͢ɺ࢒೦ͳ͕Β…
  21. σʔλܕ - Object JavaScript ʹ͓͍ͯɺ΄΅શͯͷΠϯελϯεͷܕ͸ `Object` ͱͯ͠ѻΘΕ͍ͯ·͢ɻͲ͏ ͍͏͜ͱ͔ͱ͍͏ͱɺ΄΅શͯͷΠϯελϯεͷܕ͸ `Object` ͷ

    prototype ͔Βܧঝ͞Εͯ ͍·͢ɻ const o = {} console.log(o instanceof Object) const arr = [] console.log(arr instanceof Object) const fn = function(){} console.log(fn instanceof Object) ͢΂ͯtrueͰ͢ɻ
  22. σʔλܕ - Object ʮ΄΅શͯʯͱॻ͖·͕ͨ͠ɺ΍ΓํʹΑͬͯ͸Objectͷprototypeܧঝ͔Β֎ΕΔ͜ͱ͕ ՄೳͰ͢(ES2015Ҏ߱)ɻ Object.create ͱݺ͹ΕΔܧঝݩΛ໌ه͢Δؔ਺Λ࢖͏ͱprototypeܧঝΛ࣮ݱͰ͖·͕͢ɺ ͜ͷ Object.create ʹ

    null Λ౉ͤ͹ Object ͷ prototype͔Β֎ΕͨinstanceΛ࡞Δ͜ͱ͕ ՄೳͰ͢ɻ var a = Object.create(null) console.log(a instanceof Object) Կʹ࢖͏͔ͱ͍͏ͱɺ "hasOwnProperty" ΍ "toString" ͱ͍ͬͨ૊ΈࠐΈͷϝιου͢Β ΋ෆཁͷ७ਮͳobjectΛ࡞Γ͍ͨ࣌ʹར༻͠·͢ɻΑ͋͘Δͷ͸࿈૝഑ྻͷ୅ΘΓͱ͍͏ ϢʔεέʔεͰ͢Ͷɻ
  23. σʔλܕ - Object JavaScript ͷ String, Number, Boolean ͲΕ΋࣮͸ Object

    ʹ΋ͳΓಘ·͢ɻ ͜ͷล͕ຊ౰ʹconfusableͰ͕͢ɺࣅͨΑ͏ͳ࿩͸ଞͷݴޠʹ΋͋ΔͷͰ͓͍֮͑ͯͯԼ͞ ͍ɻ string, number, boolean ͸ϦςϥϧͰ "hoge", 1, true ͱॻ͍ͨ࣌͸primitive ܕͰ͕͢ɺ Ϋϥε͔ΒnewͰinstanceԽͨ࣌͠͸ Object ʹͳΓ·͢ɻ new String("hoge") instanceof Object // true "hoge" instanceof Object // false new Number(1) instanceof Object // true 1 instanceof Object // false new Boolean(false) instanceof Object // true true instanceof Object // false
  24. Ϋϥε JavaScript ʹ͸ ES2015 ͔Β class ߏจ͕ೖΓ·ͨ͠ɻ ͋͘·Ͱclassߏจͱ͸͍͑ɺΫϥεͱ͍͏৽͍֓͠೦ʹͳΔΘ͚Ͱ͸ͳ͘ɺprototypeϕʔ εͷؔ਺Ͱ͢ɻ class

    A { foo() { console.log("A") } } typeof A // => "function" ؔ਺Ͱ͋Δ͕Ώ͑ʹࣜͱͯ͠୅ೖ΋ՄೳͰ͢ɻ const A = class {}
  25. Ϋϥε ܧঝ͢Δࡍʹ͸ extends ۟Λ࢖͍·͢ɻ class A extends B { foo()

    { console.log("A") } } const a = new A() a instanceof A // true a instanceof B // true super ۟Λ࢖͏ͱ਌ͷΦϒδΣΫτʹΞΫηεͰ͖·͢ɻ
  26. Ϋϥε ϏϧτΠϯΦϒδΣΫτ΋ܧঝՄೳͰ͢ɻ class MyArray extends Array {} class MyError extends

    Error {} class MyNumber extends Number {} ಛʹErrorͷ֦ு͸errorStackΛյͣ͞ʹܧঝͰ͖ΔͨΊศར
  27. ৚݅෼ذ if, else, switchΛ࢖ͬͯϓϩάϥϜͷ৚݅෼ذΛهड़͢Δ͜ͱ͕ՄೳͰ͢ɻ if, else, switch͸શͯ"จ"Ͱ͋Γɺ"ࣜ"Ͱ͸ͳ͍ͷͰม਺એݴ΋୅ೖ΋ෆՄೳͰ͢ɻ const a =

    true if (a) { console.log("passed") } else { console.log("not here") } const b = "foo" switch (b) { case "foo": console.log("foo is here") break // ͜͜ͷbreakΛ๨ΕΔͱԼͷbar·Ͱߦ͘ case "bar": console.log("bar is here") break }
  28. ϧʔϓ ϧʔϓ͸܁Γฦ͠Կ͔Λ࣮ߦ͢ΔͨΊͷγϯϓϧͳํ๏Λఏڙ͍ͯ͠Δɻ JavaScriptͰ͸͍ΘΏΔɺ for, while, do-while, for..ofͱ͍ͬͨํ๏͕͋Δɻ for (let i=0;

    i<100; i++) { console.log(i) } let i = 0 while(i < 100) { console.log(i) i++ } let i = 0 do { console.log(i) i++ } while(i<100)
  29. ϧʔϓ ϧʔϓͷதͰ΋ for .. of ϧʔϓ͸ಛघͳͷͰ͓֮͑ͯ͘ͱྑ͍Ͱ͢ɻ Iterable (܁Γฦ͠Մೳ)ͳ΋ͷΛ܁Γฦ࣌͢ͷಛผͳforจͰ͢ɻ for (const

    a of [1, 2, 3]) { console.log(a) } ܁Γฦͨ͠ࡍʹ৽͍͠ม਺Λఆ͍ٛͯ͠ΔͨΊɺ `const a` Ͱ࢝ΊΔ͜ͱ͕ՄೳͰ͢ɻ
  30. ഑ྻͷߴ֊ؔ਺ ArrayͷforEach, filter, map, reduceͱ͍ͬͨؔ਺Λड͚औͬͯ݁ՌΛ࣮ߦ͢Δͷ͕഑ྻͷத ͷૢ࡞ͱͯ͠ೖ͍ͬͯ·͢ɻ [1, 2, 3, 4,

    5, 6, 7].filter(x => x % 2 === 1).map(x => x + 1).reduce((acc, val) => acc + val) // 20 ͜ΕΒͷߴ֊ؔ਺͸ඇৗʹΑ͘࢖͍·͢ɻ͓͖֮͑ͯ·͠ΐ͏ɻ
  31. ๻ͷߏஙͨ͠HTML <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Todo Manager</title> </head>

    <body> <form method="POST" action="/todos"> <input type="text" > <input type="submit" > </form> <div> <ul> <li><input type="checkbox">test</li> <li><input type="checkbox">test</li> <li><input type="checkbox">test</li> <li><input type="checkbox">test</li> </ul> </div> </body> </html>
  32. ΫϥΠΞϯτΛॻ͘ # public/js ҎԼʹԼهͷεΫϦϓτΛ࡞Δ controller.js - HTML͔ΒmodelͱviewΛܨ͙΋ͷ view.js - දࣔΛ࡞Δ΋ͷ

    model.js - fetchͯ͠஋Λऔಘ͢Δ΋ͷ main.js - ΦϒδΣΫτ؅ཧɺى఺ͱ࣮ͯ͠ߦ͞ΕΔ΋ͷ ίʔυΛͪΒݟ͠ͳ͕ΒҰॹʹॻ͍͍ͯ͜͏ɻ
  33. TestΛॻ͘ • test Λॻ͘ʹ͸ͦͷ··Ͱ͸μϝͳͷͰAPI΍ constantsͷ஋͕ࠩ͠ସ͑ΒΕΔΑ͏ʹ͢Δඞ ཁ͕͋Δɻ • ͜ΕΛ Test Double

    ͱ͍͏ // globalͷ஋Ͱࠩ͠ସ͑ΒΕΔΑ͏ʹ͓ͯ͘͠ɻ const TODO_URL = global.TODO_URL || '/todos'; const fetch = global.fetch;
  34. TestΛॻ͘ # test ϥϯφʔΛೖΕΔ $ npm install eater --save-dev #

    mock ͷ fetch ΛೖΕΔ $ npm install node-fetch --save-dev # package.json ͷ scripts.test ͷͱ͜ΖΛҎԼͷΑ͏ʹ͢Δ ``` "test": "eater", ``` # test/client/todo.model.js Λॻ͍ͯத਎Λॻ͘
  35. TestΛॻ͘ # test/client/todo.model.js Λॻ͍ͯத਎Λॻ͘ const assert = require('assert'); const test

    = require('eater/runner').test; const agreedServer = require('agreed-server'); const fetch = require('node-fetch'); test('check todo instance', () => { global.todo = {}; require('../../public/js/model'); assert(global.todo.model) }); # npm test $ npm test
  36. JavaScriptͰαʔόΛ࡞Δ • express ΛΠϯετʔϧͯ͠αʔόΛ࡞ͬͯ ΈΔ • npm install express —save

    • express ͰstaticαʔόΛ࡞Δ • express ͰϦΫΤετΛॲཧ͢Δ
  37. JavaScriptͰαʔόΛ࡞Δ $ npm install express --save $ vim app.js ```

    'use strict'; const express = require('express'); const app = express(); const PORT = process.env.PORT || 3000; app.use(express.static('./public/')); app.listen(PORT, () => { console.log(`Listening in ${PORT}`); }); ``` $ node app.js
  38. JavaScriptͰαʔόΛ࡞Δ # APIͷ஋Λฦ͢ $ npm install body-parser --save ``` 'use

    strict'; const express = require('express'); const bodyParser = require('body-parser'); const todoRouter = require('./server/todo-router'); const app = express(); const PORT = process.env.PORT || 3000; app.use(bodyParser.json()); app.use(express.static('./public/')); app.use('/todos', todoRouter); app.listen(PORT, () => { console.log(`Listening in ${PORT}`); }); ```