CloudPloy

Node.js Deployment Guide

Deploy Node.js applications on CloudPloy with automatic scaling, environment configuration, and performance optimization.

Getting Started

Deploy your Node.js application to CloudPloy in minutes with our streamlined deployment process.

✅ Prerequisites

  • • Node.js application with package.json
  • • Git repository (GitHub, GitLab, or Bitbucket)
  • • CloudPloy account
  • • Basic understanding of Node.js and npm

Step 1: Connect Repository

  1. Log into your CloudPloy dashboard
  2. Click "New Application"
  3. Select "Node.js" as your framework
  4. Connect your Git repository
  5. Choose the branch to deploy (typically main/master)

Step 2: Automatic Detection

CloudPloy automatically detects your Node.js application and configures:

  • • Node.js version from package.json engines field
  • • Package manager (npm, yarn, or pnpm)
  • • Build scripts and dependencies
  • • Start command from package.json scripts
  • • Port configuration (default: 3000)

Zero Configuration: Most Node.js applications deploy automatically without additional setup.

Project Setup Requirements

Ensure your Node.js project is properly configured for deployment on CloudPloy.

package.json Configuration

{
  "name": "my-nodejs-app",
  "version": "1.0.0",
  "description": "My Node.js application",
  "main": "server.js",
  "engines": {
    "node": ">=18.0.0",
    "npm": ">=8.0.0"
  },
  "scripts": {
    "start": "node server.js",
    "build": "npm run build:assets",
    "dev": "nodemon server.js",
    "test": "jest"
  },
  "dependencies": {
    "express": "^4.18.0",
    "dotenv": "^16.0.0"
  },
  "devDependencies": {
    "nodemon": "^2.0.0",
    "jest": "^29.0.0"
  }
}

Server Configuration

// server.js
const express = require('express');
const app = express();

// Use PORT environment variable provided by CloudPloy
const PORT = process.env.PORT || 3000;

app.get('/', (req, res) => {
  res.json({ message: 'Hello from CloudPloy!' });
});

app.listen(PORT, '0.0.0.0', () => {
  console.log(`Server running on port ${PORT}`);
});

Health Check Endpoint

// Add health check endpoint for monitoring
app.get('/health', (req, res) => {
  res.status(200).json({
    status: 'healthy',
    timestamp: new Date().toISOString(),
    uptime: process.uptime()
  });
});

// Graceful shutdown handling
process.on('SIGTERM', () => {
  console.log('SIGTERM received, shutting down gracefully');
  server.close(() => {
    process.exit(0);
  });
});

💡 Best Practices

  • • Always bind to 0.0.0.0 (not localhost) for container compatibility
  • • Use process.env.PORT for dynamic port assignment
  • • Include health check endpoints for monitoring
  • • Implement graceful shutdown handling

Deployment Configuration

Customize your Node.js deployment settings for optimal performance and reliability.

Build Configuration

Automatic Build Process

  1. Install dependencies with npm ci (or yarn install --frozen-lockfile)
  2. Run npm run build if build script exists
  3. Prune development dependencies for production
  4. Generate optimized Docker image
  5. Deploy to CloudPloy infrastructure

Custom Build Commands

Override default build behavior in your application settings:

# Custom build commands example
BUILD_COMMAND="npm run build:production"
START_COMMAND="npm start"
INSTALL_COMMAND="npm ci --only=production"

# For apps requiring additional setup
POST_BUILD_COMMAND="npm run db:migrate"

Node.js Version Management

Supported Node.js Versions

LTS (Recommended)

18.x

Long Term Support

Current

20.x

Latest Features

Legacy

16.x

Maintenance Mode

Performance Optimization

🚀 Automatic Optimizations

  • • Node.js clustering enabled by default
  • • Gzip compression for static assets
  • • HTTP/2 support enabled
  • • CDN integration for asset delivery
  • • Memory and CPU monitoring

Environment Variables

Configure environment variables for your Node.js application securely.

Setting Environment Variables

  1. Navigate to your application dashboard
  2. Go to Settings > Environment Variables
  3. Add your environment variables:
    • • Key: Variable name (e.g., DATABASE_URL)
    • • Value: Variable value
    • • Encrypted: Toggle for sensitive data
  4. Click "Save" to apply changes
  5. Redeploy application to use new variables

Common Environment Variables

# Database Configuration
DATABASE_URL=postgresql://user:password@host:5432/database
MONGODB_URI=mongodb://user:password@host:27017/database

# API Keys (mark as encrypted)
JWT_SECRET=your-secret-key
STRIPE_SECRET_KEY=sk_live_...
SENDGRID_API_KEY=SG....

# Application Settings
NODE_ENV=production
LOG_LEVEL=info
SESSION_SECRET=your-session-secret

# External Services
REDIS_URL=redis://host:6379
ELASTICSEARCH_URL=http://host:9200

Using Environment Variables

// Load environment variables (optional with CloudPloy)
require('dotenv').config();

// Access environment variables
const config = {
  port: process.env.PORT || 3000,
  database: {
    url: process.env.DATABASE_URL,
    pool: {
      min: parseInt(process.env.DB_POOL_MIN) || 2,
      max: parseInt(process.env.DB_POOL_MAX) || 10
    }
  },
  jwt: {
    secret: process.env.JWT_SECRET,
    expiresIn: process.env.JWT_EXPIRES_IN || '7d'
  },
  redis: {
    url: process.env.REDIS_URL
  }
};

module.exports = config;

🔒 Security Best Practices

  • • Mark sensitive variables as encrypted
  • • Never commit secrets to version control
  • • Use different values for staging and production
  • • Rotate secrets regularly
  • • Use strong, unique values for JWT secrets

Scaling Configuration

Configure automatic scaling for your Node.js application based on traffic and resource usage.

🎛️ Scaling Options

Vertical Scaling

  • • CPU: 0.5 - 8 vCPUs
  • • Memory: 512MB - 16GB RAM
  • • Automatic scaling based on usage
  • • No downtime scaling

Horizontal Scaling

  • • Instances: 1 - 50 replicas
  • • Load balancing included
  • • Health check-based routing
  • • Zero-downtime deployments

Auto-Scaling Rules

  1. Navigate to Settings > Scaling
  2. Configure scaling triggers:
    • • CPU Threshold: Scale up when CPU > 70%
    • • Memory Threshold: Scale up when memory > 80%
    • • Request Rate: Scale based on requests per second
    • • Response Time: Scale when latency increases
  3. Set scaling limits (min/max instances)
  4. Configure cooldown periods

Load Balancing

⚡ Built-in Load Balancing

  • • Round-robin request distribution
  • • Health check-based routing
  • • Sticky sessions support
  • • SSL termination at load balancer
  • • Automatic failover handling

Resource Monitoring

Monitor your application's resource usage and scaling events:

  • • Real-time CPU and memory graphs
  • • Request rate and response time metrics
  • • Scaling event logs and history
  • • Cost optimization recommendations
  • • Performance alerts and notifications

Next Steps

Need Help Deploying Node.js Apps?

Our team can help you deploy and optimize your Node.js applications on CloudPloy.