🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to Node.js Notes
Topic #5

Node.js vs Browser


Key Differences

Node.js and browsers both run JavaScript, but they have different environments and capabilities.

Node.js is designed for server-side development, while browsers are for client-side applications.

  • APIs: Node.js provides APIs for file system, networking, and OS, which browsers do not. Browsers provide DOM, fetch, and UI APIs not available in Node.js.
  • Global Objects: Node.js uses global; browsers use window or self.
  • Modules: Node.js uses CommonJS (require) and ES modules (import); browsers use ES modules or plain <script> tags.
  • Security: Browsers run in a sandbox with limited access; Node.js has full access to the file system and network.
  • Event Loop: Both environments use an event loop, but Node.js has additional APIs for timers, process, etc.
  • Environment Variables: Node.js can access environment variables (process.env); browsers cannot.
  • Package Management: Node.js uses npm/yarn; browsers use CDNs or bundlers.

This page explains the key differences, with examples for each environment.


Examples

Global Objects

// Node.js
global.mylet = 42;
console.log(global.mylet); // 42

File Access

// Node.js
const fs = require('fs');
fs.readFile('myfile.txt', 'utf8', (err, data) => {
  if (err) throw err;
  console.log(data);
});

HTTP Requests

// Node.js
const https = require('https');
https.get('https://example.com', res => {
  let data = '';
  res.on('data', chunk => data += chunk);
  res.on('end', () => console.log(data));
});

Modules

// Node.js (CommonJS)
const fs = require('fs');

Comparison Table

Feature Node.js Browser
File System Access Yes No
Networking (TCP/UDP) Yes No
DOM Access No Yes
Global Object global window/self
Modules CommonJS/ESM ESM/Scripts
Environment Variables Yes (process.env) No
Security Full OS access Sandboxed
Package Management npm/yarn CDN/Bundler

Want to go beyond the notes?

Join CodingNow 2.0's Node.js course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Node.js vs Browser – FAQs

Quick answers about learning Node.js vs Browser in Node.js.

This free note from CodingNow 2.0 explains Node.js vs Browser in Node.js — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Node.js topic on CodingNow 2.0, including Node.js vs Browser, is 100% free with no signup required.
With focused practice, most students grasp Node.js vs Browser in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now