Getting Started with Node.js: Install, Setup, and Hello
이 글의 핵심
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
| Aspect | Browser JavaScript | Node.js |
|---|---|---|
| Environment | Browser (Chrome, Firefox, …) | Server, local machine |
| Global | window | global |
| DOM | Yes | No |
| File system | No | Yes (fs) |
| HTTP server | No (without bundling/workarounds) | Yes (http, https) |
| Modules | ES Modules (modern) | CommonJS + ES Modules |
| Package manager | None built-in | npm, yarn, pnpm |
Shared JavaScript APIs
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
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
- nodejs.org → download LTS
- Run the installer
- 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
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
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
{
"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](/en/blog/nodejs-series-02-modules/.
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](/en/blog/nodejs-series-05-filesystem/ 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
- [Node.js module system](/en/blog/nodejs-series-02-modules/
- [Async programming](/en/blog/nodejs-series-03-async/
- [Express.js](/en/blog/nodejs-series-04-express/
Resources
Related posts
- Node.js series
- JavaScript introduction
- [Modules: CommonJS and ES modules](/en/blog/nodejs-series-02-modules/
자주 묻는 질문 (FAQ)
Q. 이 내용을 실무에서 언제 쓰나요?
A. Node.js tutorial for beginners: install Node and npm on Windows, macOS, and Linux, run Hello World, use npm scripts, and… 실무에서는 위 본문의 예제와 선택 가이드를 참고해 적용하면 됩니다.
Q. 선행으로 읽으면 좋은 글은?
A. 각 글 하단의 이전 글 또는 관련 글 링크를 따라가면 순서대로 배울 수 있습니다. C++ 시리즈 목차에서 전체 흐름을 확인할 수 있습니다.
Q. 더 깊이 공부하려면?
A. cppreference와 해당 라이브러리 공식 문서를 참고하세요. 글 말미의 참고 자료 링크도 활용하면 좋습니다.
같이 보면 좋은 글 (내부 링크)
이 주제와 연결되는 다른 글입니다.
- [Node.js Module System: CommonJS and ES Modules Explained](/en/blog/nodejs-series-02-modules/
- JavaScript 시작하기 | 웹 개발의 필수 언어 완벽 입문
- Node.js 시작하기 | 설치, 설정, Hello World
이 글에서 다루는 키워드 (관련 검색어)
Node.js, JavaScript, Backend, Server, npm, Tutorial, Beginner 등으로 검색하시면 이 글이 도움이 됩니다.