Htop reporting multiple processes running, when in reality it's just one

I am noticing something weird when running a node express server on Balena Cloud. In fact, I am installing htop in my container, and when i run it I get multiple processes, all running that same node server. What’s happening? I am attaching the Dockerfile and a screenshot of the htop result:

FROM balenalib/raspberrypi3-python:3-stretch-run as builder

RUN install_packages make

WORKDIR /usr/src/app

COPY . ./

RUN curl -sL | bash && \
    apt-get install -y nodejs python-dev build-essential gcc iotop htop ctop

FROM builder

RUN npm install

# Enable udevd so that plugged dynamic hardware devices show up in our container.

# will run when container starts up on the device
ENTRYPOINT [ "node", "bin/www" ]

Hello, do you experience the same results when running the application on your own machine? Also, would you mind sharing what is in the application startup script? Keep in mind that there several popular node process managers that may start your server in cluster mode which starts several processes

@nazrhom no it does not happen on other machines (i see only one /bin/www process running). Also, it seems to happen regardless of node. For example, you can see below a container running the code from github.

My node application does not use any process manager (forever, pm2 or any of those), just plain npm.

@nazrhom looks like htop shows threads, not processes. If we want to only see the main thread we need to press H apparently. So things make more sense now.

What I am still unsure about is why multiple threads are being shown for the node process. I always thought node was single-threaded…

Oh, I had just stumbled in the same thread, wasn’t aware of that. As far as as node being single thread that is true, but it is to be interpreted as: there is one thread that runs JS code. The runtime will still have a thread pool that takes care of the blocking (IO, ecc) operations; for example when you call a function like readFile the JS thread will hand off the blocking system call to one of these threads. This way the JS thread can continue executing while the other one is reading the file, eventually the JS thread will get the results and run the callback.