How to create and deploy a Next.js app on Server4Agent

Create a Next.js 16 app on a persistent server and put it online from your AI assistant. We ran it end to end: the exact commands, timings, memory and gotchas.

Nov 4, 202610 min read

Next.js is the most common answer when you ask an AI assistant for a web app, and the hardest part has never been writing it. It is getting it to run somewhere other than a laptop: a server with Node on it, a process that stays up, a port, a public address.

Server4Agent is that server. Your assistant reaches it over MCP, creates a Next.js app on it, builds it and puts it online at a live URL that keeps working after the conversation ends.

We ran every step below on a brand-new small Server4Agent server on November 4, 2026, and wrote down what happened: how long each step took, how much memory the build used, and the two places it can trip you up.

On this page: Quick answer · The prompt · Step by step · Measurements · Server size · Environment variables · Updating · Existing app · Troubleshooting · FAQ

Quick answer

To create a Next.js app on Server4Agent, connect Server4Agent to your AI assistant, then have it run these steps on a server:

  • Create a project on a server. A new project is an empty, private folder with its own URL.
  • Scaffold the app into that empty folder with npx create-next-app@latest . --yes, in the background, because it takes a few minutes.
  • Build it with npm run build, also in the background.
  • Start it with start_app and the command npm start. Next.js reads the port Server4Agent gives it, so there is nothing to configure.
  • Deploy it, which opens the project and returns its address on apps.server4agent.com.

On a small server, the whole thing took about ten minutes from creating the server to a live page, and the app keeps running after the chat ends.

Key takeaways

  • Scaffold first, into the empty folder. create-next-app refuses a folder that has anything in it, and Server4Agent adds a .server4agent/ folder once an app has started there.
  • Run the long steps in the background. Server4Agent's exec returns output for about 20 seconds. Scaffolding took 4.7 minutes and the build took 56 seconds, so each goes to a log file that the assistant reads until it is done.
  • No port settings. next start reads the PORT variable that start_app sets and listens on every interface by default.
  • A small server can build the starter. The build peaked at about 856 MB and finished without running out of memory. Give a growing app a medium server.
  • `NEXT_PUBLIC_` values are baked in at build time. Set them before you build, and rebuild when they change.
  • Private by default. The URL serves nothing until you deploy, and you can keep it to your team or behind a password.

The prompt to give your assistant

Connect Server4Agent once from the integrations page, in whichever AI assistant you use. Then paste this. It spells out the two gotchas, so the assistant does not have to discover them:

text
Create a new Next.js app on Server4Agent and put it online.
Reuse a running server with room if I have one, otherwise create a small one.
Create a project first, then scaffold the app into the empty project folder
with npx create-next-app@latest . --yes, before anything else is written there.
Run long commands in the background with their output in a log file under /tmp,
and read the log until each one finishes. Build it with npm run build, start it
with start_app and the command npm start, deploy it, and send me the URL.

Then ask for what you actually want: "Turn the home page into a pricing calculator for our three plans," or "add a page that lists the open support tickets from our API." Each change follows the same loop: edit, build, restart.

Step by step: what happens on the server

These are the tool calls behind that prompt, with the commands we ran. You can also make them yourself through the REST API or the SDKs.

Step 1: a server

list_servers finds a running server with room for another project. If there is none, create_server makes one. Ours took about two minutes to go from created to ready, and the assistant polls get_server until provisioning reads ready.

The box we got ran Node.js 22.23 and npm 10.9. Next.js 16 needs Node.js 20.9 or later, so nothing needs installing.

Step 2: a project

create_project makes the project and returns two things the rest depends on: a project_id and the listen_port, the port its URL is routed to. Ours was 8100. The project starts private, so nothing is reachable yet.

Step 3: scaffold the app

exec, in the project, runs the scaffold in the background and sends its output to a log file outside the project folder:

bash
nohup npx --yes create-next-app@latest . --yes --use-npm > /tmp/create-next-app.log 2>&1 &

Then the assistant checks on it every minute or so:

bash
tail -5 /tmp/create-next-app.log

--yes takes the recommended defaults: TypeScript, ESLint, Tailwind CSS, the App Router and Turbopack. On November 4 that meant Next.js 16.4.5 and React 19.3.0. Most of the 4.7 minutes was npm install, which left 491 MB in node_modules.

Two details matter here. The . means "this folder", which is the project folder, so the app's package.json sits where start_app will look for it. And the log goes to /tmp because create-next-app refuses a folder with any unexpected file in it, a log file included.

Step 4: build it

bash
nohup npm run build > /tmp/next-build.log 2>&1 &

The build is done when the log ends with the route table and ○ (Static) prerendered as static content. Ours compiled in 28.7 seconds, checked types in 17.8 seconds, and finished in 56 seconds, using one build worker.

Step 5: start it

start_app with the command npm start. It runs next start in the background with PORT set to the project's port, records the command so the app comes back after a restart, and waits for the port to answer. Ours reported Ready in 1316ms.

There are no flags to add. According to the Next.js documentation, next start takes its port from the PORT environment variable and listens on 0.0.0.0 unless told otherwise, which is exactly what Server4Agent's proxy needs.

Step 6: deploy it

deploy checks that something is listening on the project's port, opens the project and returns its URL. Ours answered with HTTP 200 straight away, with the home page served prerendered from Next.js's own cache.

What we measured

All on one new small server, on November 4, 2026, with the default create-next-app starter.

StepTimeNotes
Server, created to readyAbout 2 minutesNode.js 22.23, npm 10.9
create-next-app and npm install4 minutes 41 secondsNext.js 16.4.5, React 19.3.0, 491 MB of node_modules
next build56 secondsOne worker. Peak memory about 856 MB, no out-of-memory kill
next start1.3 seconds to readyAbout 95 MB of memory while serving
deployLive on the first callHTTP 200, page served from the Next.js cache

Two things stand out. At its peak the build used about 856 MB of the server's memory, while the whole server sat at about 340 MB with the app running and serving, so the build decides the server size, not the traffic. And even the starter app's build came close to what a small server allows.

Which server size you need

Small builds and runs a new Next.js app, as the run above shows. It is the size on the Free and Starter plans.

Medium is the safer home once the app grows: more pages, more dependencies, heavier images. Build memory grows with the app, and a medium server has more of it. Server4Agent's own import form says the same thing: when you import a repository from the dashboard, it reads package.json and suggests a medium server when it finds Next.js. Medium comes with the Pro plan and up. See pricing.

The reason to care: if a build runs a server out of memory, the server restarts, and every project on it goes offline for that moment. Apps started with start_app come back on their own, but a crowded small server is the wrong place to build a large Next.js app. Give it a server of its own, or a bigger one.

Environment variables and secrets

Next.js reads two kinds of environment variables, and they arrive at different times.

  • Server-side values, such as a database URL or an API key, are read while the app runs. Store them as Server4Agent secrets with set_secret and attach_secret, or pass secrets to create_project. The app gets them as environment variables when start_app starts it. Restart the app after changing one.
  • `NEXT_PUBLIC_` values are written into the JavaScript bundle during next build. Set them before you build, and rebuild after any change. Commands run with exec in a project get its secrets too, so the build sees them.

Secret values are write-only: no tool ever reads one back. And you never set PORT yourself. The Next.js docs note that it cannot come from a .env file anyway, and Server4Agent sets it for you.

Updating the app

Every change follows the same three steps:

  • Edit. The assistant writes the changed files with write_file, for example app/page.tsx.
  • Rebuild. npm run build in the background, as before.
  • Restart. start_app again with the same name. Calling it again is how a running app picks up the new build.

The project keeps its slug and URL through all of this, so "add a chart to the dashboard" a week later edits the same app at the same address. If something breaks, get_logs shows the app's log, and that is where the error usually is.

Deploying a Next.js app you already have

If the app already lives in a Git repository, skip the scaffold:

  • Create the project from the repository. create_project takes a git source: the URL, an optional branch, a subdir for a monorepo, and a clone token stored as a secret for a private repository. In the dashboard this is Import from Git.
  • Install, build, start. npm ci and npm run build in the background, then start_app with npm start, then deploy. The same steps as above, minus the scaffold.

If you would rather not drive it yourself, Server4Agent's on-server agent can bring an imported project up for you. That run spends AI credits from your plan, while running the commands yourself does not.

What self-hosting Next.js gets you

The Next.js documentation's self-hosting guide describes a Node.js server running next start as supporting every Next.js feature. A Server4Agent project is exactly that, with two details the guide cares about already in place:

  • A proxy in front. The guide recommends a reverse proxy rather than exposing the Next.js server directly. Every Server4Agent project is reached through one.
  • A persistent disk. The guide says the default cache, which incremental static regeneration and next/image use, works on its own for a single instance with persistent local disk. A project's folder persists between restarts, so it does.

For the wider trade-off between this and a serverless platform, see Vercel or a server: where should what your AI agent builds live?.

Troubleshooting

What you seeWhyWhat to do
"The directory ... contains files that could conflict"create-next-app found something in the project folder, such as a log file or .server4agent/Write logs to /tmp, and scaffold before starting anything. In a folder that is no longer empty, scaffold into web and start with npm --prefix web start
exec returns with no outputThe command is still running past about 20 secondsRun it in the background with output to a log file, then read the log
"Could not find a production build in the '.next' directory"The app was started before the build finishedWait for the build log to show the route table, then call start_app again
The server restarted during a buildThe build ran out of memoryUse a medium server, or one with fewer projects on it
The URL says "Temporarily unavailable"Nothing is listening on the project's portRead get_logs, fix what crashed, and call start_app again
The URL lands on "Nothing found"The project is still privateCall deploy
A NEXT_PUBLIC_ value is missing or oldIt was set after the buildRebuild, then restart with start_app
Changes do not showThe app is still serving the previous buildRebuild, then call start_app again with the same name

FAQ

Can I host a Next.js app on Server4Agent?

Yes. A Server4Agent project runs Next.js the way its documentation describes for self-hosting, as a Node.js server started with next start, and serves it at a live URL on apps.server4agent.com. We created, built and deployed a new Next.js 16 app on a small server in about ten minutes.

Which version of Next.js does it install?

Whatever create-next-app@latest installs on the day. On November 4, 2026 that was Next.js 16.4.5 with React 19.3.0. Server4Agent's servers run Node.js 22, and Next.js 16 needs Node.js 20.9 or later.

What size server do I need for Next.js?

A small server built and ran the default starter in our test, with the build peaking at about 856 MB of memory. Build memory grows with the app, so a medium server, available on the Pro plan and up, is the safer choice for anything larger.

How long does it take?

In our run, about two minutes for a new server, 4.7 minutes to scaffold and install, 56 seconds to build and 1.3 seconds to start. Reusing a running server skips the first step.

Do I need to configure the port or hostname?

No. next start reads the PORT environment variable, which Server4Agent sets for every app it starts, and listens on all interfaces by default.

Does the app keep running after the conversation ends?

Yes. It runs on a persistent server, not in the chat, and Server4Agent records its start command so it comes back after a restart, a pause or a resume.

Is the app public as soon as it is deployed?

New projects are private until you deploy them. You can then keep a project to your team, so opening it takes a Server4Agent sign-in, or put it behind a password.

Can I deploy a Next.js app I already have?

Yes. Create the project from its Git repository, including a subfolder of a monorepo or a private repository with a clone token, then install, build, start and deploy it the same way.

Does next/image work?

The Next.js documentation says image optimization works with no configuration when the app runs with next start, which is how it runs on Server4Agent.

How do I update the app later?

Change the files, run npm run build again, then call start_app again with the same name to restart on the new build. The URL stays the same.

External references

About Server4Agent

Server4Agent is a hosted server for AI agents. Your assistant builds a tool, site, API or bot on it from a plain-English request and ships it to a live URL, private by default and under a hard budget cap. Connect it from the integrations page.

Questions, or a tool you want built?

Ask us about this post, or tell us what you would hand to an assistant first. A person reads every message and answers within one business day.