basic module
๋ชจ๋ ์ฌ์ฉํ๊ธฐ
node.js์์ ์์ฃผ ์ฌ์ฉํ๋ ํจ์์ ๊ฒฝ์ฐ ๋ณ๋์ js ํ์ผ์ ๋ง๋ค์ด ์ฃผ๋ฉด ๋๋๋ฐ ์ด ๋ ๋ชจ๋์ด๋ผ๋ ๊ฐ๋ ์ ์ฌ์ฉํ๋ค.
node.js์์๋ jsํ์ผ์ด ํ๋์ ๋ชจ๋์ด ๋๋ฉฐ ์ด๋ ํ๋์ ๊ฐ์ฒด ๋จ์๋ก ์๊ฐํ๋ฉด ๋๋ค.
exports ๊ฐ์ฒด์ ํ์ํ ํจ์๋ฅผ ์ถ๊ฐํ์ฌ ์ค๋ค.
exports.f2 = function(){
console.log("f2 ํจ์ํธ์ถ");
}
require ํจ์๋ฅผ ์ด์์ ๋ชจ๋ ๊ฐ์ฒด๋ฅผ ์์ฑํ๋ค
var test = require("/.second.js");
๋ชจ๋ ๊ฐ์ฑ๋ฅผ ์ด์ฉํด ํจ์๋ฅผ ํธ์ถํ๋ค.
test.f2();
node.js ๋ ๋ชจ๋์ด๋ผ๋ ๊ฐ๋ ์ ์ฌ์ฉํ์ฌ ์ธ๋ถ ํ์ผ์ ๊ธฐ๋ฅ์ ๊ฐ์ ธ๋ค ์ฌ์ฉํ ์ ์๋ค.
Last updated
Was this helpful?