From Frontend to Backend - Understanding Node.js & Servers
Before we dive into building APIs, let's establish a solid foundation in server-side JavaScript and understand how it differs from the browser environment you might be familiar with.
Node.js vs Browser JavaScript
<aside>
🔄
Same Language, Different Runtime
Node.js and browser JavaScript share the same language syntax, but they run in fundamentally different environments with different capabilities and constraints.
</aside>
Browser JavaScript
- Environment: Runs in the browser's JavaScript engine (V8 in Chrome, SpiderMonkey in Firefox)
- Primary Purpose: Manipulate the DOM, handle user interactions, make HTTP requests
- Global Object:
window
- APIs Available: DOM API, Web APIs (fetch, localStorage, etc.)
- Security: Sandboxed environment with restrictions (CORS, no file system access)
- Module System: ES Modules, script tags
Node.js JavaScript
- Environment: Runs on the server using Chrome's V8 engine
- Primary Purpose: Build servers, access file systems, interact with databases
- Global Object:
global
(or globalThis
)
- APIs Available: File system, networking, process management, crypto
- Security: Full system access (must implement your own security)
- Module System: CommonJS historically, now also ES Modules
Feature |
Browser JS |
Node.js |
DOM Access |
✅ Yes |
❌ No |
File System Access |
❌ Limited |
✅ Full |
Network Servers |
❌ No |
✅ Yes |
Process Control |
❌ No |
✅ Yes |
Package Management |
📦 Limited |
📦 npm/yarn/pnpm |
What is Node.js to JavaScript?