MyInternships.in

Node.js Basics

Node.js vs Browser JavaScript

The language is identical; the environment is not. The browser gives you the DOM, fetch and localStorage; Node gives you the file system, processes and network servers. Code that assumes the wrong environment fails immediately.


What is vs Browser JavaScript in Node.js?

The language is identical; the environment is not. The browser gives you the DOM, fetch and localStorage; Node gives you the file system, processes and network servers. Code that assumes the wrong environment fails immediately.

Key points to remember

  • Shared code must avoid environment-specific APIs, or guard them at runtime.
  • fetch, AbortController and structuredClone are now available in both.
  • Node cannot manipulate a page; it can only generate HTML to send.

What exists where

APIBrowserNode.js
document, windowyesno
localStorageyesno
fs, path, osnoyes
processnoyes
fetchyesyes (Node 18+)
Buffernoyes
setTimeout, Promise, JSONyesyes

Common mistakes with vs Browser JavaScript

  • Copying browser code that touches document into a Node script.
  • Assuming localStorage exists on the server in a server-rendered application.

Node.js vs Browser JavaScript— Interview Questions & FAQs

Can I use the same JavaScript in Node and the browser?+

The language features, yes. The environment APIs, no — anything touching the DOM only works in a browser, and anything touching the file system only works in Node.

Related Node.js Topics

Keep learning with these closely related lessons.

Ready to use your Node.js skills?

Find verified Node.js internships and fresher developer jobs across India.

Browse Node.js Internships