v3.2
API Status Dashboard

Next.js → Installation & Setup

Deploy and scale Next.js applications on CloudNexus infrastructure in minutes. Learn how to initialize, configure, and deploy your project with optimized edge routing and serverless functions.

✅ Next.js 14+ Supported ⚡ App Router Ready 🌍 Edge Network

Prerequisites

Before getting started, ensure your development environment meets the following requirements:

ℹ️
CloudNexus fully supports both the Pages Router and App Router. The App Router is recommended for new projects due to improved streaming and edge compatibility.

Step 1: Install CloudNexus CLI

If you haven't already installed the CloudNexus CLI, run the following command:

bash
npm install -g @cloudnexus/cli

# Authenticate with your account
cn auth login

Step 2: Initialize Next.js Project

Create a new Next.js application or navigate to an existing one:

bash
# Create new project
npx create-next-app@latest my-app
cd my-app

# Or use an existing project directory
cd /path/to/your-nextjs-app

Step 3: CloudNexus Configuration

Initialize the CloudNexus configuration file in your project root:

bash
cn init nextjs

This creates a cloudnexus.config.js file with optimized defaults:

javascript
export default {
  framework: "nextjs",
  region: "auto", // Auto-selects nearest edge region
  runtime: "edge",
  buildCommand: "next build",
  outputDirectory: ".next",
  environment: {
    nodeVersion: "18",
    standalone: true, // Optimizes bundle size
    imageOptimization: "cloudnexus" // Uses our native imgproxy
  }
};
💡
Setting standalone: true enables Next.js standalone output, reducing cold start times by 60% on our serverless runtime.

Step 4: Environment Variables

Add your environment variables to the CloudNexus dashboard or via CLI:

bash
# Set variables directly
cn env set DATABASE_URL=postgresql://...
cn env set NEXT_PUBLIC_API_KEY=your_key_here

# Or sync from .env file
cn env sync .env.production
⚠️
Never commit sensitive .env files to version control. CloudNexus automatically masks secrets in build logs.

Step 5: Build & Deploy

Push your code to a supported Git provider (GitHub, GitLab, or Bitbucket) or deploy directly:

bash
# Deploy from local directory
cn deploy --prod

# Preview deployment (auto-generated URL)
cn deploy --preview

# Check deployment status
cn logs --follow

Once deployed, your application will be available at:
https://your-project.cloudnexus.app

Troubleshooting

Build fails with "Module not found"

Ensure standalone: true is set in next.config.js and that all dependencies are listed in package.json. CloudNexus builds in an isolated container environment.

Edge runtime compatibility errors

Edge functions don't support native Node.js modules like fs or path. Use cloudnexus-native alternatives or mark API routes with runtime: 'nodejs'.

Image optimization not working

Verify imageOptimization: "cloudnexus" is set. If using custom domains, ensure CORS headers are configured correctly.