Node.js Guide
Deploy Node.js applications on Kova.
Quick Start
Basic Express App
version: "2.0"
services:
api:
image: node:20-alpine
expose:
- port: 3000
as: 3000
to:
- global: true
env:
- NODE_ENV=production
- PORT=3000
params:
storage:
app:
mount: /app
source: uploads
profiles:
compute:
api:
resources:
cpu:
units: 1
memory:
size: 512Mi
deployment:
api:
anywhere:
profile: api
count: 1
Project Structure
Upload these files to /app:
/app
├── package.json
├── index.js
└── node_modules/ (installed on container)
package.json
{
"name": "my-api",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"express": "^4.18.0"
}
}
index.js
const express = require('express');
const app = express();
const port = process.env.PORT || 3000;
app.get('/', (req, res) => {
res.json({ message: 'Hello from Kova!' });
});
app.get('/health', (req, res) => {
res.json({ status: 'ok' });
});
app.listen(port, () => {
console.log(`Server running on port ${port}`);
});
Using with Database
services:
api:
image: node:20-alpine
expose:
- port: 3000
as: 3000
to:
- global: true
env:
- DATABASE_URL=postgres://postgres:password@db:5432/mydb
- NODE_ENV=production
db:
image: postgres:15-alpine
env:
- POSTGRES_PASSWORD=password
- POSTGRES_DB=mydb
Use Docker service names (like db) as hostnames for inter-service communication.
Environment Variables
Common environment variables for Node.js apps:
| Variable | Description |
|----------|-------------|
| NODE_ENV | Set to production |
| PORT | Port your app listens on |
| DATABASE_URL | Database connection string |
| REDIS_URL | Redis connection string |