Differences between Node and the Browser
By Flavio Copes
Understand the key differences between writing JavaScript for Node.js and the browser, from the missing DOM and filesystem access to CommonJS versus ES modules.
Both the browser and Node use JavaScript as their programming language.
Building apps that run in the browser is a completely different thing than building a Node.js application.
Despite the fact that it’s always JavaScript, there are some key differences that make the experience radically different.
As a frontend developer who extensively uses Javascript, Node apps brings with it, a huge advantage - the comfort of programming everything, the frontend and the backend, in a single language.
You have a huge opportunity because we know how hard it is to fully, deeply learn a programming language, and by using the same language to perform all your work on the web - both on the client and on the server, you’re in a unique position of advantage.
What changes is the ecosystem.
In the browser, most of the time what you are doing is interacting with the DOM, or other Web Platform APIs like Cookies. Those do not exist in Node, of course. You don’t have the document, window and all the other objects that are provided by the browser.
And in the browser, we don’t have all the nice APIs that Node.js provides through its modules, like the filesystem access functionality.
Another big difference is that in Node.js you control the environment. Unless you are building an open source application that anyone can deploy anywhere, you know which version of Node you will run the application on. Compared to the browser environment, where you don’t get the luxury to choose what browser your visitors will use, this is very convenient.
This means that you can write modern JavaScript that your Node version supports. On a current LTS release like Node 24, that covers almost everything you use day to day.
In the browser the picture is different. You don’t pick the browser your visitors use, and some run old versions. Modern browsers update themselves and understand current syntax, so transpiling everything down to ES5 with Babel is no longer the default. You may still do it for the older clients you need to support.
Modules used to be another sharp difference.
Node supports both CommonJS (require / module.exports) and native ES Modules (import / export). You pick ESM with a .mjs file or "type": "module" in package.json. Browsers speak ES Modules natively too.
So you are not stuck with require() only in Node and import only in the browser. Both sides can use import. CommonJS still shows up a lot in older Node code and packages.
Want me to talk about your product? You can sponsor this site.
Related posts about node: