Step 12 of 12 100% complete

Step 12: Deployment and Production

What You'll Learn

  • Build your application for production
  • Configure essential environment variables
  • Run your application in production mode
  • Complete the production deployment checklist

What You'll Build

A production-ready NoEgo application deployed to the cloud.

Building for Production

Compile your TypeScript and prepare assets for production:

terminal
1
npm run build

This creates a dist/ directory with compiled JavaScript and optimized assets.

Understanding the dist/ Output

After building, your dist/ directory contains the production-ready application:

dist/ structure
1
2
3
4
5
6
7
8
9
10
11
dist/
├── no_ego.js            # Production bootstrap (runs backend + frontend)
├── src/
│   ├── server/          # Compiled server code + SQL files
│   ├── ui/              # Compiled frontend TS/JS (mirrors source tree)
│   └── middleware/      # Compiled middleware
├── .app/
│   ├── assets/          # Client bundle (Vite output)
│   └── ssr/             # SSR bundle (Forge output)
├── src/server/openapi/  # Copied API OpenAPI + stitch files
└── src/ui/openapi/      # Copied UI OpenAPI + stitch files

The compiled output is optimized for Node.js and ready to run without any additional build step.

Environment Variables

Configure your application for production using these essential environment variables:

.env.production
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Required for production
NODE_ENV=production

# Server configuration
PORT=3000

# Security - REQUIRED: Set a strong secret for session cookies
COOKIE_SECRET=your-strong-secret-key-here

# Database
DATABASE_PATH=./data/production.sqlite

# Logging
LOG_LEVEL=info

Important: COOKIE_SECRET

The COOKIE_SECRET is used to sign session cookies and should be a long, random string. In production, generate it using: openssl rand -base64 32

Access environment variables in your application configuration:

src/config.ts
1
2
3
4
5
6
7
export const config = {
  port: Number(process.env.PORT) || 3000,
  database: process.env.DATABASE_PATH || "./data/app.sqlite",
  cookieSecret: process.env.COOKIE_SECRET || "dev-secret-change-in-production",
  logLevel: process.env.LOG_LEVEL || "debug",
  isProduction: process.env.NODE_ENV === "production",
};

Running in Production

Start your application in production mode with the following command:

terminal
1
NODE_ENV=production node dist/no_ego.js

For a more robust setup, use a process manager like PM2:

terminal
1
2
3
4
5
6
7
8
9
10
11
# Install PM2 globally
npm install -g pm2

# Start with PM2
pm2 start dist/no_ego.js --name "my-noego-app"

# View logs
pm2 logs my-noego-app

# Restart on file changes (useful for staging)
pm2 restart my-noego-app

Production Checklist

Before deploying to production, ensure you've completed these steps:

  • Environment Variables: All required variables are set (NODE_ENV, PORT, COOKIE_SECRET)
  • Database Migrations: Run npx proper up before starting
  • Build Verification: npm run build completes without errors
  • Static Assets: dist/.app/assets is present and served via dist/no_ego.js
  • Database Backups: Backup strategy is configured
  • Logging: Production logging is enabled for monitoring
  • Security: COOKIE_SECRET is a strong, unique value

Docker Deployment

Create a Dockerfile for containerized deployment:

Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
FROM node:20-alpine

WORKDIR /app

COPY package*.json ./
RUN npm ci --only=production

COPY dist ./dist
COPY migrations ./migrations
COPY proper.json ./

ENV NODE_ENV=production

EXPOSE 3000

CMD ["node", "dist/no_ego.js"]
terminal
1
2
3
4
5
6
7
8
# Build the image
docker build -t my-noego-app .

# Run the container
docker run -p 3000:3000 \
  -e COOKIE_SECRET=your-secret-here \
  -v $(pwd)/data:/app/data \
  my-noego-app

Platform Deployment

NoEgo applications can be deployed to any Node.js hosting platform:

  • Railway: Connect your GitHub repo for automatic deployments
  • Fly.io: Use their CLI with fly launch
  • DigitalOcean: App Platform supports Node.js directly
  • AWS/GCP: Use container services or serverless options

Monitoring in Production

Add proper logging for production monitoring:

src/middleware/request_logger.ts
1
2
3
4
5
6
7
8
9
10
11
12
import type { Request, Response, NextFunction } from "express";

export default function requestLogger(req: Request, res: Response, next: NextFunction) {
  const start = Date.now();

  res.on("finish", () => {
    const duration = Date.now() - start;
    console.log(`${req.method} ${req.originalUrl} - ${res.statusCode} (${duration}ms)`);
  });

  next();
}
🎉

Congratulations!

You've completed the NoEgo tutorial!

What You Built

Over these 12 steps, you've created a full-stack application with:

  • Project scaffolding and structure
  • Svelte 5 UI with runes ($state, $props)
  • OpenAPI routing with Forge
  • Database migrations with Proper
  • Type-safe queries with SQLStack
  • Repository → Service → Controller architecture
  • API endpoints with validation
  • Frontend integration with page loaders
  • Form handling and data mutations
  • Production-ready deployment

Next Steps

Ready to build more? Here are some ideas to extend your application:

  • Add User Authentication: Implement login, registration, and session management
  • Implement Real-time Updates: Add WebSocket support for live data
  • Add File Upload Support: Allow users to upload images and files
  • Explore Advanced SQLStack: Learn about joins, transactions, and complex queries

Dive deeper into the framework with our comprehensive documentation.

Troubleshooting

NoEgo

© 2025 NoEgo. All rights reserved.