하나의 파일에 모든 기능을 작성하는 대신, 관련 있는 함수나 변수, 클래스 등을 별도의 파일로 묶어서 관리
module.exports 또는 exports 객체에 내보내고 싶은 변수나 함수, 객체 할당require() 함수를 사용const hello = () => {
console.log("Hello");
};
module.exports = {
hello,
};
const helloModule = require("./hello.js");
helloModule.hello();
export 키워드 사용import 키워드 사용Node.js에서 ESM을 사용하려면,
package.json파일에"type": "module"을 추가하거나 파일 확장자를.mjs로 사용해야 함
export const hello = () => {
console.log("Hello");
};
import { hello } from "./helloModule.js";
// ...