0Pricing
Node.js Backend Development Bootcamp · Ders

Node.js Modül Sistemi Açıklaması

CommonJS modüllerini, ES modüllerini ve Node.js'te işlevlerin dosyalar arasında nasıl içe ve dışa aktarılacağını keşfedin.

Node.js Modül Sistemi Açıklaması, CoddyKit'te ücretsiz bir Node.js Backend Development Bootcamp dersidir. Bu, 4 dersinin 2. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Node.js Backend Development Bootcamp öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Node.js Backend Development Bootcamp kursu toplamda 4 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

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.

Sıkça Sorulan Sorular

“Node.js Modül Sistemi Açıklaması” dersi ücretsiz mi?

Evet — “Node.js Modül Sistemi Açıklaması” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Node.js Backend Development Bootcamp kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Node.js Backend Development Bootcamp kursu toplamda 4 dersten oluşur.

“Node.js Modül Sistemi Açıklaması” dersinde ne öğreneceğim?

CommonJS modüllerini, ES modüllerini ve Node.js'te işlevlerin dosyalar arasında nasıl içe ve dışa aktarılacağını keşfedin. Node.js Backend Development Bootcamp ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.

Node.js Backend Development Bootcamp öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te Node.js Backend Development Bootcamp, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 2. dersidir.

“Node.js Modül Sistemi Açıklaması” dersi ne kadar sürer?

Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.

Bu Node.js Backend Development Bootcamp dersinde kod yazıp çalıştırabilir miyim?

Evet. Her Node.js Backend Development Bootcamp dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.

Bu kursun tüm dersleri

  1. Node.js ve NPM'ye Giriş
  2. Node.js Modül Sistemi Açıklaması
  3. Eşzamansız JavaScript ve Olay Döngüsü
  4. Dosya Sistemi ve Akışlarla Çalışma
← Node.js Backend Development Bootcamp Sayfasına Dön