โGenerate the smallest possible Node.js Express app with a single route that returns JSON, plus a /health route. Include package.json and index.js.โ
01 โ Choose a simple app to containerize
Category: Dockerfile ยท Priority: High ยท Step: 2
Keep it minimal โ a single route returning JSON is enough. The focus is the Docker setup, not the app.
๐ฏ What is this task?
Before writing any Docker code, you need a real app to containerize. Don't build something complex โ a single web page that returns a message is enough. The goal here is to have working code you can wrap in Docker.
๐ค AI Prompt to generate the app
Copy and paste this into Claude or ChatGPT:
"Create a simple Node.js Express app. It should have two routes:
GET /that returns a JSON response{ "message": "Hello from Docker!" }, andGET /healththat returns{ "status": "ok" }. Use port 3000. Put everything in a single file calledindex.js. Also create apackage.jsonfor it."
๐ Step-by-step
Step 1 โ Install Node.js (if not installed)
Go to https://nodejs.org and download the LTS version. After installing, verify it works:
node --version
npm --version
Both commands should print a version number.
Step 2 โ Create a project folder
mkdir my-docker-app
cd my-docker-app
Step 3 โ Create the files
Create index.js with this content:
const express = require('express');
const app = express();
const PORT = process.env.PORT || 3000;
app.get('/', (req, res) => {
res.json({ message: 'Hello from Docker!' });
});
app.get('/health', (req, res) => {
res.json({ status: 'ok' });
});
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
Create package.json with this content:
{
"name": "my-docker-app",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"express": "^4.18.2"
}
}
Step 4 โ Install dependencies and test it locally
npm install
npm start
Open your browser and go to http://localhost:3000 โ you should see the JSON response. Press Ctrl+C to stop.
โ Done when
- You have an
index.jsandpackage.jsonin your folder - Running
npm startshows the server running message -
http://localhost:3000shows{ "message": "Hello from Docker!" } -
http://localhost:3000/healthshows{ "status": "ok" }
๐ Quiz
Answer all 2 questions correctly to complete this lesson.