0Pricing
Node.js Backend Development Bootcamp · 강의

Node.js 모듈 시스템 설명

CommonJS 모듈과 ES 모듈을 살펴보고 Node.js에서 파일 간에 기능을 가져오고 내보내는 방법을 배웁니다.

Node.js 모듈 시스템 설명은(는) CoddyKit의 무료 Node.js Backend Development Bootcamp 강의입니다. 이것은 4개 중 2번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Node.js Backend Development Bootcamp 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Node.js Backend Development Bootcamp 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

Organize Your Code with Modules

As apps grow, one giant file gets messy. Modules split code into small, reusable, focused pieces. Node supports two systems: CommonJS and ES Modules.

CommonJS: `require()` & `module.exports`

CommonJS is Node's original module system: require() pulls code in, module.exports pushes code out. Import what you need, export what you offer.

CommonJS: Exporting a Function

Here's mathUtils.js. Whatever you assign to module.exports is what other files can import from it — here, just the add function.

const add = (a, b) => a + b;
const subtract = (a, b) => a - b;

module.exports = add; // Only 'add' is exported

CommonJS: Importing and Using

In another file, require('./mathUtils.js') pulls in that exported function. Keep both files in the same folder and run node app.js.

const addFunction = require('./mathUtils.js');

console.log("Using the imported function:");
console.log(`5 + 3 = ${addFunction(5, 3)}`);
console.log(`10 + 2 = ${addFunction(10, 2)}`);

CommonJS: Exporting Multiple Items

Need to export several things? Assign an object to module.exports holding all of them — a clean way to group related utilities.

const greet = (name) => `Hello, ${name}!`;
const farewell = (name) => `Goodbye, ${name}!`;

module.exports = {
  greetUser: greet,
  sayGoodbye: farewell
};

CommonJS: Importing Multiple Items

When a module exports an object, grab pieces with destructuring: const { greetUser, sayGoodbye } = require(...). Cleaner and clearer than dot access.

const { greetUser, sayGoodbye } = require('./utils.js');

console.log(greetUser('Alice'));
console.log(sayGoodbye('Bob'));

ES Modules: The Modern Standard

ES Modules (ESM) are JavaScript's official standard, using import/export. They enable tree-shaking — set "type": "module" or use .mjs to opt in.

ESM: Named Exports & Imports

With named exports, you export values by name and import them in matching { } braces — making it obvious exactly which parts you're using.

export const add = (a, b) => a + b;
export const multiply = (a, b) => a * b;

// app.mjs (main entry point)
// To run this: ensure package.json has "type": "module"
// and run with `node app.mjs`
import { add, multiply } from './calculator.mjs';

console.log(`2 + 4 = ${add(2, 4)}`);
console.log(`5 * 6 = ${multiply(5, 6)}`);

ESM: Default Exports

A module can have one default export, usually its main feature. Import it under any name you like, no braces needed.

const logMessage = (msg) => console.log(`[LOG] ${msg}`);
export default logMessage;

// main.mjs (main entry point)
// To run this: ensure package.json has "type": "module"
// and run with `node main.mjs`
import myLogger from './logger.mjs';

myLogger('This is a default message.');
myLogger('Another important event.');

Quick Check: Module Systems

You've learned about CommonJS and ES Modules. Let's test your understanding!

Recap: Node.js Modules

You've explored Node modules: CommonJS (require/module.exports, the classic) and ESM (import/export, the modern standard). Both keep apps organized.

자주 묻는 질문

“Node.js 모듈 시스템 설명” 강의는 무료인가요?

네 — “Node.js 모듈 시스템 설명” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Node.js Backend Development Bootcamp 강의 전체를 잠금 해제할 수 있습니다. Node.js Backend Development Bootcamp 강의에는 총 4개의 강의가 포함되어 있습니다.

“Node.js 모듈 시스템 설명”에서 뭘 배우나요?

CommonJS 모듈과 ES 모듈을 살펴보고 Node.js에서 파일 간에 기능을 가져오고 내보내는 방법을 배웁니다. 브라우저에서 직접 실행하는 실습 코드로 Node.js Backend Development Bootcamp을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Node.js Backend Development Bootcamp을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Node.js Backend Development Bootcamp은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 2번째 강의입니다.

“Node.js 모듈 시스템 설명” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Node.js Backend Development Bootcamp 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Node.js Backend Development Bootcamp 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. Node.js와 NPM 입문
  2. Node.js 모듈 시스템 설명
  3. 비동기 JavaScript와 이벤트 루프
  4. 파일 시스템 및 스트림 다루기
← Node.js Backend Development Bootcamp(으)로 돌아가기