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.
Prerequisites
Before getting started, ensure your development environment meets the following requirements:
- Node.js 18.17 or later (LTS recommended)
- Package Manager: npm 9+, yarn 1.22+, or pnpm 8+
- CloudNexus CLI installed and authenticated
- Active CloudNexus account with at least the
Developerplan
Step 1: Install CloudNexus CLI
If you haven't already installed the CloudNexus CLI, run the following command:
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:
# 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:
cn init nextjs
This creates a cloudnexus.config.js file with optimized defaults:
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
}
};
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:
# 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
.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:
# 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.