Node.js is a JavaScript runtime environment, effectively a way to run JavaScript without a browser, such as for creating a web application server that can serve HTTP clients.
Express is a web framework for Node.js, an approach that makes it easier to write web applications by providing a body of common code.
Using a Container-based approach that facilitates reproducible, isolated application deployment.
With Docker and Docker Compose we can deploy and manage container-based Node.js applications.
Assuming you have a unix-like machine available such as linux or macos, this is all quite straightforward. I’m going to assume a linux machine running Ubuntu and that Homebrew is available to keep the length of this to a minimum.
docker and docker-compose can be installed either:
-
by the OS package manager:
sudo apt install docker docker-compose -
by Homebrew:
brew install docker docker-compose
docker build . --tag dhutty/node-web-app
docker compose up --detach
curl -i http://localhost:8080which should give you output that looks somewhat like:
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: text/html; charset=utf-8
Content-Length: 11
ETag: W/"b-Ck1VqNd45QIvq3AZd8XYQLvEhtA"
Date: Fri, 09 Dec 2022 00:09:57 GMT
Connection: keep-alive
Keep-Alive: timeout=5
Hello World-
You might want to use the Express generator at least to get a feel for how Express applications are commonly organized.
-
Express provides examples;
params,error-pages,hello-worldandweb-serviceare probably the first to look at for many use cases. -
https://github.com/nodejs/docker-node/blob/main/docs/BestPractices.md