📚 StoneJS Developer Guide
Complete reference for building modern web applications with the StoneJS Framework
🚀 Deployment
Production Checklist
Essential steps to prepare your StoneJS application for production deployment:
| Item | Description | Priority |
|---|---|---|
NODE_ENV=production |
Enables production optimizations and disables debug output | Critical |
| Database Sessions | Use SESSION_STORE=database for persistent sessions |
Critical |
Strong SESSION_SECRET |
Generate with openssl rand -base64 32 |
Critical |
| HTTPS Enabled | Use SSL/TLS certificates for encrypted connections | Critical |
| Database SSL | Set DB_SSL=true for secure database connections |
High |
| Reverse Proxy | Configure nginx or similar for load balancing | High |
| Error Logging | Set up centralized logging (Winston, Bunyan, etc.) | High |
| Remove Demo Pages | Delete or protect /demo folder |
Medium |
Environment Variables
# Production .env
NODE_ENV=production
# Database
DB_TYPE=postgresql
DB_HOST=your-prod-db-host
DB_PORT=5432
DB_USER=prod_user
DB_PASSWORD=strong-password
DB_NAME=prod_database
DB_SSL=true
# Sessions
SESSION_SECRET=very-strong-random-secret
SESSION_STORE=database
SESSION_DB_HOST=your-session-db
SESSION_DB_USER=session_user
SESSION_DB_PASSWORD=session-password
SESSION_DB_NAME=sessions
# Application
PORT=3000
Using PM2 (Recommended)
PM2 is a production process manager for Node.js that handles clustering, monitoring, and auto-restarts.
Installation
npm install -g pm2
PM2 Commands
| Command | Description |
|---|---|
pm2 start stonejs-app.js --name stonejs |
Start application with a friendly name |
pm2 logs stonejs |
View real-time logs |
pm2 restart stonejs |
Restart application (zero-downtime) |
pm2 stop stonejs |
Stop application |
pm2 delete stonejs |
Remove from PM2 process list |
pm2 list |
Show all running processes |
pm2 monit |
Monitor CPU and memory usage |
pm2 startup |
Generate startup script for auto-restart on reboot |
pm2 save |
Save current process list for auto-restart |
✅ Auto-Restart on Reboot: Run pm2 startup then pm2 save to ensure your application starts automatically after server restarts.
Nginx Reverse Proxy
server {
listen 80;
server_name yourdomain.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_cache_bypass $http_upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Docker Deployment
# Dockerfile
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --production
COPY . .
EXPOSE 3000
CMD ["node", "stonejs-app.js"]
# docker-compose.yml
version: '3.8'
services:
app:
build: .
ports:
- "3000:3000"
environment:
- NODE_ENV=production
- DB_HOST=db
depends_on:
- db
restart: unless-stopped
db:
image: postgres:15
environment:
- POSTGRES_DB=myapp
- POSTGRES_USER=myuser
- POSTGRES_PASSWORD=mypassword
volumes:
- pgdata:/var/lib/postgresql/data
restart: unless-stopped
volumes:
pgdata:
Removing Demo Pages
Before deploying to production, remove demo pages:
# Delete demo directory
rm -rf pages/demo
# Or move to backup location
mv pages/demo pages/demo.backup
Monitoring
// Add error logging
process.on('uncaughtException', (err) => {
console.error('Uncaught Exception:', err);
// Send to error tracking service (Sentry, etc.)
});
process.on('unhandledRejection', (reason, promise) => {
console.error('Unhandled Rejection at:', promise, 'reason:', reason);
});
Best Practices
- Use process manager (PM2, systemd)
- Set up automatic restarts on failure
- Monitor memory usage and performance
- Use HTTPS in production (Let's Encrypt)
- Implement rate limiting
- Set up automated backups
- Use environment-specific configs
- Enable database SSL connections
Need more help?