Page 81 - Nodejs 교과서 개정2판
P. 81
module.exports = {
odd,
even,
};
WBS KTী ߸ࣻ ف ѐܳ ࢶ೮णפ ӒܻҊ module.exportsী ߸ٜࣻਸ ёܳ ੑ೮णפ ઁ
ੌ ݽٕ۽ࢲ ӝמפ ߸ٜࣻਸ ݽইك ݽٕ غח Ѫભ ܲ ੌীࢲ ੌਸ ࠛ۞য়ݶ module.ex
portsী ੑػ чਸ ࢎਊೡ ࣻ णפ
ߣীח WBS KTܳ ଵઑೞח GVOD KTܳ ࢿೞѷणפ
func.js
const { odd, even } = require('./var');
function checkOddOrEven(num) {
if (num % 2) { // 홀수면
return odd;
}
return even;
}
module.exports = checkOddOrEven;
require ೣࣻ উী ࠛ۞ৢ ݽٕ ҃۽ܳ णפ ਤ ઁীࢲח э ಫ؊ উী ੌਸ ٜ݅݅ ܲ ಫ
؊ী ח ੌب ݽٕ۽ ࢎਊೡ ࣻ णפ require ೣࣻ ੋࣻ۽ ઁҕೞח ҃۽݅ ੜ ೞݶ ؾפ
ੌ ҃۽ীࢲ KTա KTPO э ഛח ࢤۚೡ ࣻ णפ
ઁ ٘ীࢲ require ೣࣻ۽ WBS KTী ؍ чٜਸ ࠛ۞য়Ҋ णפ const { odd, even } ীࢲ
ࢸݺೠ &4 ޙߨੑפ WBS KT module.exportsী ѹ ؍ ёܳ ࠛ۞৬ GVOD KTীࢲ ࢎਊೞח ݽण
ੑפ
WBS KTীࢲ ߸ࣻܳ ࠛ۞ৡ ٍ ं ഓਸ ౸߹ೞח ೣࣻܳ ࢶ೮णפ ӒܻҊ द module.exportsী ೣ
ࣻܳ ੑ೮णפ ۧѱ ܲ ݽٕ WBS KT ਸ ࢎਊೞח ੌਸ द ݽٕ GVOD KT ۽ ٜ݅ ࣻ णפ ژೠ m
odule.exportsীח ё݅ ੑ೧ঠ ೞח Ѫ ইפۄ ೣࣻա ߸ࣻܳ ੑ೧ب ؾפ
݄݃ਵ۽ JOEFY KTܳ ࢿפ
index.js
const { odd, even } = require('./var');
const checkNumber = require('./func');
function checkStringOddOrEven(str) {