Build your LumenJS app for production and deploy it anywhere that runs Node.js.
Run the build command to generate optimized client and server bundles:
lumenjs build --project ./my-app
This creates a .lumenjs/ directory in your project root with the following structure:
Serve the production build with the built-in Express server:
lumenjs serve --project ./my-app --port 3000
The production server handles:
1. SSR rendering: pages are rendered on the server with loader data
2. Static assets: serves hashed files from .lumenjs/client/ with long cache headers
3. Loader endpoints: /__nk_loader/* for client-side navigation data fetching
4. Subscribe endpoints: /__nk_subscribe/* for SSE live data streams
5. API routes: /api/* endpoints with named HTTP method handlers
6. i18n: translation JSON served from /__nk_i18n/*
LumenJS apps are straightforward to containerize. Here's a minimal Dockerfile:
# Build stage FROM node:18-alpine AS build WORKDIR /app COPY package*.json ./ RUN npm ci COPY . . RUN npx lumenjs build # Production stage FROM node:18-alpine WORKDIR /app COPY --from=build /app/.lumenjs ./.lumenjs COPY --from=build /app/package*.json ./ COPY --from=build /app/locales ./locales RUN npm ci --omit=dev EXPOSE 3000 CMD ["npx", "lumenjs", "serve", "--port", "3000"]
.lumenjs/ build output, node_modules (production deps only), and locales/ if you use i18n. Source files are not needed at runtime.
Loaders run on the server, so they have full access to process.env. Use environment variables for secrets, API keys, and configuration:
// pages/dashboard.ts export async function loader() { const res = await fetch(process.env.API_URL + '/stats', { headers: { Authorization: `Bearer ${process.env.API_KEY}` }, }); return { stats: await res.json() }; }
When running behind nginx or a load balancer, proxy all traffic to the LumenJS server. The server handles all routing internally:
# nginx.conf server { listen 80; server_name example.com; location / { proxy_pass http://localhost:3000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }