צרו תיקייה חדשה ואתחלו פרויקט Node.js (npm init -y)
התקינו express:
npm i express
צרו src/index.js עם שרת Express פשוט שמאזין על פורט 3000
const express = require('express');
const app = express();
const PORT = 3000;
app.get('/', (req, res) => {
res.send('Hello from Express!');
});
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
start script ל-package.json{
"name": "simple-express-app",
"version": "1.0.0",
"description": "Simple Express application",
"main": "app.js",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"express": "^4.9.2"
}
}
npm run start
Dockerfile עם node:22-alpine כ-base image.dockerignore שמתעלם node_modulesinstruction ENV מגדיר משתנה סביבה בתוך ה-image. הקוד יכול לקרוא אותו בזמן ריצה.