← Back to Node.js Menu | 🏠 Hub
| Feature | Browser JS | Node.js |
|---|---|---|
| Environment | Browser tab | Server / Terminal |
| DOM | ✅ document, window | ❌ မရှိဘူး |
| File System | ❌ | ✅ fs module |
| HTTP Server | ❌ | ✅ http/express |
| Database | ❌ direct | ✅ mysql2, pg, mongoose |
| Package manager | CDN | npm / yarn / pnpm |
# 1. Download: nodejs.org → LTS version (Long Term Support) # 2. Install → restart terminal # Version check node --version # v20.x.x npm --version # 10.x.x # Run a JS file node app.js # REPL (Read-Eval-Print Loop) — interactive node > 2 + 2 4 > "Hello".toUpperCase() 'HELLO' > .exit # quit REPL
// app.js
console.log("Hello from Node.js!");
console.log("Node version:", process.version);
console.log("Platform:", process.platform);
console.log("Current dir:", process.cwd());
// run: node app.js
// Output:
// Hello from Node.js!
// Node version: v20.11.0
// Platform: win32
// Current dir: C:\projects\myapp
// Browser: window, document, navigator, location
// Node.js: process, __dirname, __filename, global
// process — current process info
process.env.NODE_ENV // "development" | "production"
process.argv // command line arguments
process.exit(0) // exit (0 = success)
process.env.PORT // environment variable
// __dirname / __filename
console.log(__dirname); // C:\projects\myapp
console.log(__filename); // C:\projects\myapp\app.js
// setTimeout, setInterval — same as browser
setTimeout(() => console.log("After 1s"), 1000);
// setImmediate — after current event loop iteration
setImmediate(() => console.log("Immediate"));
// Command line args
// run: node app.js --name=Ko --age=25
const args = process.argv.slice(2);
console.log(args); // ['--name=Ko', '--age=25']
// Node.js is SINGLE-THREADED but NON-BLOCKING
// Event loop = handle async operations without multiple threads
console.log("1. Start");
setTimeout(() => {
console.log("4. Timeout (after 0ms — after current loop)");
}, 0);
setImmediate(() => {
console.log("3. Immediate");
});
Promise.resolve().then(() => {
console.log("2. Promise (microtask — runs first!)");
});
console.log("5. End");
// Output order:
// 1. Start
// 5. End
// 2. Promise (microtask)
// 3. Immediate
// 4. Timeout
← Node.js Menu | Next: Node.js 02 → Modules →