Why doesn’t Node.js have a native DOM?

The DOM is the DOM, and the JavaScript implementation is simply a separate entity. The DOM represents a set of facilities that a web browser exposes to the JavaScript environment. There’s no requirement however that any particular JavaScript runtime will have any facilities exposed via the global object.

What Node.js is is a stand-alone JavaScript environment completely independent of a web browser. There’s no intrinsic link between web browsers and JavaScript; the DOM is not part of the JavaScript language or specification or anything.

I use the old Rhino Java-based JavaScript implementation in my Java-based web server. That environment also has nothing at all to do with any DOM. It’s my own application that’s responsible for populating the global object with facilities to do what I need it to be able to do, and it’s not a DOM.

Note that there are projects like jsdom if you want a virtual DOM in your Node project. Because of its very nature as a server-side platform, a DOM is a facility that Node can do without and still make perfect sense for a wide variety of server applications. That’s not to say that a DOM might not be useful to some people, but it’s just not in the same category of services as things like process control, I/O, networking, database interop, and so on.

There may be some “official” answer to the question “why?” out there, but it’s basically just the business of those who maintain Node (the Node Foundation now). If some intrepid developer out there decides that Node should ship by default with a set of modules to support a virtual DOM, and successfully works and works and makes that happen, then Node will have a DOM.

Leave a Comment