Next.js

Practical guide to host Next.js applications on Discloud.

🧭 Introduction

This step-by-step guide shows how to prepare, configure, and deploy a Next.js application on Discloud.

There are two main approaches:

  • Option A (recommended) – use next build + next start without a custom server (only the built-in Next.js server).

  • Option B – use a custom server with Express, useful when you need extra routes, custom middleware, or specific integrations.

Additionally, we show an alternative with static export, ideal for purely static websites.

This guide assumes you already have a Next.js project running locally.


📋 Requirements


🧱 Local prerequisites

Before continuing, you will need:

  • Node.js installed on your machine.

  • A Next.js project created (e.g. npx create-next-app).

  • A Discloud account with a configured subdomain.

  • Optionally: Git, VSCode, and/or the Discloud CLI to make the workflow easier.

If you are not yet familiar with the local environment, check:

NodeJS

🧹 Preparing project files

Before compressing your project into a .zip, create a .discloudignore file in the project root to exclude unnecessary files and folders from the upload:

The .discloudignore file works similarly to .gitignore, but it is used by Discloud to ignore files at upload time.


Inside your package.json, make sure the main Next.js scripts are defined. A basic example:


✅ Option A – Deploy without custom server (Next.js "built-in")

In this option you only use the internal Next server (next start), without needing a server.js.

🔁 Basic flow

  1. Run the build locally (optional but recommended):

  2. Test locally:

  3. If everything works, prepare the .zip and upload it to Discloud.

⚙️ discloud.config (example)

🧩 Option B – Custom server with Express

If you need custom routes, middleware, or to integrate other libs before delegating to Next, you can use an Express server that runs Next internally.

🧾 server.js

Create a server.js file in the project root with the following content:

📦 package.json (with custom server)

Update your scripts to use server.js in production:

⚙️ discloud.config (custom server)

Use this option only if you really need a custom server. For most projects, Option A (no custom server) is simpler and sufficient.

🧾 Alternative – Static export (Next.js as a static site)

If your project does not depend on SSR or API Routes, you can use next export to generate a fully static site.

📦 package.json (static export)

⚙️ discloud.config (static)


🔐 Environment variables

In Next.js, public environment variables must start with NEXT_PUBLIC_.

  • Define variables via the Discloud Dashboard, CLI, or API.

  • Everything that starts with NEXT_PUBLIC_ is embedded into the bundle during the build.

Example:

Using in components:


A typical Next.js project structure for Discloud might look like:


🚀 Deploying to Discloud

You can deploy your Next.js app using any of the supported methods.

DashboardDiscord BotVisual Studio CodeCLI

🛠️ Troubleshooting (common errors)

App does not open / wrong port

Check if Next is using port 8080 (next start -p 8080 or PORT=8080).

Plan / permission error

Confirm that your account has the correct plan for websites/APIs.

Subdomain not configured

Make sure you followed the subdomain guide before deploying.

Build errors

  • Run locally: npm run build and fix any errors before uploading.

  • Check that all dependencies are listed in package.json.

Errors when starting (START)

  • Verify that the start script is correct.

  • Follow the Discloud logs to see the exact error message.

Last updated