r/AskProgramming • u/SurpriseHuge199 • Jun 23 '26
Other Why is Tomcat called a server but Node.js called a runtime?
Im currently learning Java web development and I think I've confused myself. Right now, my mental model of a Java web application is:
Frontend: HTML, CSS, JavaScript
Backend: Java (Servlets/JSP/Java EE)
Server: Tomcat
Database: MySQL (or any other database)
This setup makes sense to me. Recently I started looking at the MEAN stack:
Frontend: Angular
Backend: JavaScript
Database: MongoDB
And I always thought Node.js was basically the equivalent of Tomcat in the Java world. But then I found out that Node.js is called a runtime environment, not a server.
If Node.js isn't a server, then what exactly does it do? When a browser sends a request to a web application built with Node.js, what is actually acting as the server? I actually googled it first and watched some videos but i didn’t get the grasp of it.
More generally, what's the difference between a server and a runtime environment? I feel like I'm missing a basic concept and it's making it hard to understand how different web stacks fit together.
Looking for a beginner-friendly explanation and a simple mental model please help 🙏
14
u/bubbles33d Jun 23 '26
Java VM is a Runtime. Tomcat is the (web) server.
Node.js is a Runtime. Express is the (web) server.
38
u/Pale_Height_1251 Jun 23 '26
Node.js is a runtime, but you can run a server on that runtime.
4
u/strange-the-quark Jun 23 '26
A runtime is just a bunch of (often already compiled) code installed on a system that your own program can "draw" on, that provides supporting operations that your program is ultimately built on, and that your program calls into while its running (often indirectly - e.g. a standard library function that you call, may itself be calling into the runtime).
You can build all kinds of programs on top of this, they don't have to have anything to do with servers. A server is just a specific kind of a program that sits there and listens for incoming connections/requests, and sends responses back. Like, when you visit a web page, your browser sends a GET request to some server somewhere, and this server sends the web page back. You can write your own simple server and run it on Node.js, or you can maybe find a generic, ready-made one that also runs on Node.js. The programs that send requests to a server are referred to as clients, so your browser is a web client.
Tomcat is ultimately just a ready-made server program (with some advanced doodads) that runs on the Java Runtime Environment, which, again, is a bunch of code installed on a system that provides essential services and supports Java applications.
1
u/GreatMinds1234 Jun 23 '26
Not sure this is the right answer but tomcat is the server environment, node.js is an environment installer and requirements checker in a sense. Tomcat is the whole thing, node.js is just for the project which is installed for. I hope this gives a little bit of answer but I am hoping there will be more to the point answers that I am also looking forward to read.
1
u/prehensilemullet Jun 23 '26 edited Jun 23 '26
As far as I understand you typically run a standalone Tomcat server and deploy your code to it in a WAR file. But I don’t know of anything that supports this kind of deployment model in Node. Running an Express app is more analogous to writing code to run an embedded Tomcat server, like
And people typically use Docker containers to package and deploy Node apps, rather than a language-specific package like WAR files
3
u/dev-razorblade23 Jun 23 '26
Node.js is a runtime as it allows JS code to be run on your machine, rather then browser only...
You can however make server in JS to be run using Node... But i would not go that route as JS is single threaded, so not the best choice for high concurrency usecases
1
u/Astronaut6735 Jun 23 '26
You don't need to understand them to start programming.
1
u/Astronaut6735 Jun 23 '26
That's not pride. It's being practical. If your goal is to learn how to develop apps on the MEAN stack, diving deeper than you need to is going to side track you.
1
u/huuaaang Jun 23 '26
Node.js is the runtime. Express.js (or similar) is the server.
1
u/nwbrown Jun 23 '26
Think of Node.js as the equivalent of the JVM in the Java stack.
1
u/Plane_Water3386 Jun 23 '26
To understand you need to look at the literal definition of what each tool does.
JavaScript and Java are programming languages, which are just text instructions. A runtime is the core engine required to read that text and translate it into machine code so the physical computer processor can execute it.
Node.js and the JVM are runtimes.
A server is a specific software application designed to open a network port, listen for incoming internet requests, and return data.
Tomcat and Express.js are servers.
The structural difference between them is that Tomcat is an application that runs on top of the Java runtime and functions as a server immediately out of the box.
Node.js is solely a runtime environment. To make Node.js act as a server, you gotta write code inside of it that tells the environment to listen on a specific network port.
1
u/Jaanrett Jun 23 '26 edited Jun 23 '26
Because tomcat is a web server and node.js is a programing language interpreter.
A server is basically any program that response to requests. In the case of tomcat, I believe this is a web server, because it response to web requests by serving web pages, and it is written in java.
Node.js is in a sense, like java, in that programs can be written in it. You can make a web server using node.js, but you can also make a mad lib game in node.js
I'm not an expert in either, so grain of salt and all.
1
u/OptimistIndya Jun 24 '26
A c code will compile and generate an executable file.
You can directly run it on the type /family of machines it was compiled for.
A C code does not need a runtime. It has the instructions to the processor directly in the executable file.
Java language brings another layer between the processor and the application called runtime environment.
Java wrote a runtime environment for every OS type. And said you can run the class file in it . ( A c executable needs to be compiled and created for every OS type separately)
A java "executable" is a file (called a class file) . You can distribute a class file and if you had an OS with Jre ( Java runtime) it would run.
1
u/dallas_paley Jun 24 '26
Do a Google Image search for tomcat architecture and node.js.
1
u/National-Parsnip1516 Jun 24 '26
tbh node's 'runtime' tag is just marketing gymnastics. at the end of the day if it listens on a port and serves bytes it's a server. been using node since the callback hell days and the cognitive load of 'owning the server' vs 'running in a server' is where devs trip up. do people actually care about the runtime vs server distinction in prod or is this just interview prep slop?
1
u/SupersonicSpitfire Jun 24 '26
1
u/Ok_For_Free Jun 24 '26
Others have already given some good answers. For some reason I felt like some history might clear things up a bit.
Around a decade ago, and longer, a Java HTTP Application was built into
warfile, which is just azipfile of your compiled code and static assets. On its own, thewarfile was not a complete application. You would need to run one of the many implementations of the Java Servlet Specification first, and then upload yourwarto that Server. Tomcat, Jetty, Web Sphere are just the ones I can remember off the top of my head.Spring Boot and containerization drove the trend to build Java Servlet Servers into an executable
jar. So these days, much slimmer versions of these Servers are packaged with your code.Node.js has an HTTP Server built into it, so there was never a place for something like Tomcat. Express is still using this built in server under the hood. And when you deploy a Node.js Application, you just need to make a
zipfile of your code and static assets to run your application on any server with Node.So today, the development and deployment of Java and Node.js HTTP Applications look very similar. Servers like Tomcat implement a feature that Node.js has built in.
1
u/bubbles33d Jun 28 '26
A server runs in a loop and listens for instructions, usually a network connection request. It performs things from the request. A standard HTTP server listens to port 80. Port 8080 is a common alternative for HTTP in non-production.
A runtime is a platform and library code that runs application. It does not sit in a loop. It stops when the application stops
1
u/Dear_Dish_3513 Jun 28 '26
The names mostly come from what each project chose to emphasize. Underneath, the layers are the same. From the bottom up it's: your machine, the OS, a language runtime, then your app.
A runtime is just the thing that actually executes your code. The JVM runs compiled Java, Node runs JavaScript (it's V8 plus a bunch of I/O libraries). Neither one is a web server on its own.
A server is a program that listens on a port and answers requests. Tomcat is exactly that, written in Java, so it runs on top of the JVM. Its job is hosting servlet and JSP apps and doing the HTTP part for them, which is why people call it a servlet container.
Node is different because it ships the runtime and easy networking together, but it still doesn't hand you a server. You write the server yourself, or pull in something like Express, and Node runs it.
So Java names the two roles separately (JVM the runtime, Tomcat the server), and Node rolls the runtime and networking into one and leaves the server to you. Same stack underneath, just packaged and named differently.
2
u/Limp-Exercise-343 Jun 23 '26
lord of false statements, have meecy on thee