NodeJs: Node.js is a runtime environment that allows us to run JavaScript outside the browser, mainly on the server side.Node.js allows JavaScript to run on servers.
Used for:
1. Build backend/server applications
- APIs, Real-time apps (chat apps), REST services
2. High performance
Uses V8 engine (very fast), Non-blocking I/O
3. Real-time applications
Chat applications, Live notifications, Streaming apps
4. Full-stack JavaScript
Same language (JavaScript) for frontend and backend
Key Differences
| Feature | Node.js | Browser JavaScript |
|---|---|---|
| Runs On | Server | Browser |
| Access to | File system, OS, network | DOM, window, document |
| Module System | CommonJS / ES Modules | ES Modules |
| Global Object | global |
window |
| Use Case | Backend development | Frontend UI development |
1. Environment
Browser JS runs inside Chrome, Firefox, etc.
Node.js runs on server machines.
2. APIs
Browser has DOM APIs (document, window)
Node.js has file system (fs), HTTP module, etc.
3. Security
Browser JS is sandboxed.
Node.js has full system access.
Event Loop
The Event Loop is the core mechanism in Node.js that allows it to perform non-blocking I/O operations despite running on a single thread.
Call Stack
The Call Stack is a LIFO (Last In First Out) data structure.It keeps track of: 1] Which function is currently executing 2] What function was called from where
Callback Queue (Macrotask Queue)
The Callback Queue (also called the Task Queue or Macrotask Queue) stores:
setTimeout, setInterval, setImmediate, I/O callbacks, Network requests.
Microtask Queue (High-Level Only)
The Microtask Queue has higher priority than the callback queue.
It stores:
Promise.then(), Promise.catch(), process.nextTick(), queueMicrotask().
Top comments (0)