Node.js vs the Browser : What are the big differences

Differences between Node.js and the Browser

Both the browser and Node.js use JavaScript as their programming language – but the literal Run Time Environments are different. 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.

From the perspective of a frontend developer who extensively uses JavaScript, Node.js apps bring with them a huge advantage: the comfort of programming everything – the frontend and the backend – in a single language.

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.

  1. 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.js, of course. You don’t have the document, window and all the other objects that are provided by the browser.
  2. In the browser, we don’t have all the nice APIs that Node.js provides through its modules, like the filesystem access
  3. 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.js 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.
  4. You can use Babel to transform your code to be ES5-compatible before shipping it to the browser, but in Node.js, you won’t need that.
  5. Node.js uses the CommonJS module system, while in the browser we are starting to see the ES Modules standard being implemented. In practice, this means that for the time being you use require() in Node.js and import in the browser.