[2026] Getting Started with Node.js: Install, Setup, and Hello World

[2026] Getting Started with Node.js: Install, Setup, and Hello World

이 글의 핵심

Node.js tutorial for beginners: install Node and npm on Windows, macOS, and Linux, run Hello World, use npm scripts, and understand modules, fs, and HTTP—aligned with how production apps are built.

Introduction

What is Node.js?

Node.js is a JavaScript runtime built on Chrome’s V8 engine. It lets you run JavaScript outside the browser. Key characteristics:

  • Non-blocking I/O: High throughput for I/O-heavy workloads
  • Single-threaded model: Event loop–driven concurrency
  • Cross-platform: Windows, macOS, and Linux
  • npm: The world’s largest package ecosystem
  • One language: Share JavaScript between frontend and backend Good fits for Node.js:
  • REST and JSON APIs
  • Real-time apps (chat, games, collaboration)
  • Microservices and BFF layers
  • CLI tools and build scripts
  • Streaming and upload pipelines Poor fits:
  • CPU-heavy work (image/video transcoding, large numerical jobs)
  • Work that needs true parallel CPU crunching (use workers, native addons, or another runtime)

1. Node.js vs browser JavaScript

AspectBrowser JavaScriptNode.js
EnvironmentBrowser (Chrome, Firefox, …)Server, local machine
Globalwindowglobal
DOMYesNo
File systemNoYes (fs)
HTTP serverNo (without bundling/workarounds)Yes (http, https)
ModulesES Modules (modern)CommonJS + ES Modules
Package managerNone built-innpm, yarn, pnpm

Shared JavaScript APIs

아래 코드는 javascript를 사용한 구현 예제입니다. 비동기 처리를 통해 효율적으로 작업을 수행합니다. 각 부분의 역할을 이해하면서 코드를 살펴보시기 바랍니다.

console.log("Hello");
setTimeout(() => console.log("After 1s"), 1000);
setInterval(() => console.log("Tick"), 1000);
const fetchData = async () => {
    const result = await Promise.resolve("data");
    return result;
};
const obj = JSON.parse('{"name": "Alice"}');
const str = JSON.stringify({ name: "Alice" });

Node-only APIs

아래 코드는 javascript를 사용한 구현 예제입니다. 각 부분의 역할을 이해하면서 코드를 살펴보시기 바랍니다.

const fs = require('fs');
const content = fs.readFileSync('file.txt', 'utf8');
const http = require('http');
const server = http.createServer((req, res) => res.end('Hello'));
const path = require('path');
const filePath = path.join(__dirname, 'file.txt');
console.log(process.version, process.platform, process.cwd(), process.pid);

Prefer async fs methods on servers; sync calls block the event loop.

2. Installing Node.js

Windows

  1. nodejs.org → download LTS
  2. Run the installer
  3. Verify: node --version, npm --version

macOS

Official installer or brew install node.

Linux (Ubuntu/Debian example)

curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs

nvm

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
nvm install 20
nvm use 20

3. First programs

Hello World

console.log("Hello, Node.js!");
console.log(`Node ${process.version}, platform ${process.platform}`);

CLI arguments

아래 코드는 javascript를 사용한 구현 예제입니다. 조건문으로 분기 처리를 수행합니다. 코드를 직접 실행해보면서 동작을 확인해보세요.

console.log(process.argv);
const args = process.argv.slice(2);
if (args.length === 0) {
    console.log("Usage: node args.js <name>");
    process.exit(1);
}
console.log(`Hello, ${args[0]}!`);

Environment variables

const port = process.env.PORT || 3000;
const nodeEnv = process.env.NODE_ENV || 'development';
console.log(port, nodeEnv);

4. First HTTP server

아래 코드는 javascript를 사용한 구현 예제입니다. 각 부분의 역할을 이해하면서 코드를 살펴보시기 바랍니다.

const http = require('http');
const server = http.createServer((req, res) => {
    console.log(`${req.method} ${req.url}`);
    res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' });
    res.end('Hello from Node.js!');
});
const PORT = 3000;
server.listen(PORT, () => console.log(`http://localhost:${PORT}`));

Add routing by branching on req.url and req.method; return JSON with JSON.stringify and Content-Type: application/json.

5. npm

npm init -y
npm install express
npm install --save-dev nodemon

아래 코드는 json를 사용한 구현 예제입니다. 코드를 직접 실행해보면서 동작을 확인해보세요.

{
  "scripts": {
    "start": "node index.js",
    "dev": "nodemon index.js"
  }
}

6. Modules

CommonJS: module.exports / require. ES modules: "type": "module" in package.json, then import / export. Same patterns as the modules article.

7. File system (fs)

Sync (readFileSync), callback (readFile), and Promise (require('fs').promises) styles exist—use Promises + async/await for server code.

8. Examples

Minimal multi-route server, static file server, and CLI directory counter—see the filesystem guide for full listings.

9. nodemon

npm install --save-dev nodemon
{ "scripts": { "dev": "nodemon server.js" } }

10. Debugging

VS Code launch.json with "type": "node", or node inspect script.js.

11. dotenv

npm install dotenv

Load secrets from .env; never commit .env (list in .gitignore).

12. Common issues

  • EADDRINUSE — port busy; pick another port or kill the process
  • Cannot find module — run npm install
  • Wrong path — use path.join(__dirname, ...)
  • Async mistakes — use await / .catch() consistently

13. Tips

Typical layout: src/ (routes, controllers, utils), public/, tests/, .env, package.json. Handle uncaughtException, unhandledRejection, and graceful shutdown on SIGTERM. Use streams for large files; consider cluster for CPU-bound scaling.

Summary

Node.js is the V8-based JavaScript runtime for servers and tools. Install LTS, use npm, prefer async fs and HTTP APIs for services, and move on to modules and Express.

Next steps

Resources


... 996 lines not shown ... Token usage: 63706/1000000; 936294 remaining Start-Sleep -Seconds 3