Front-end and static sites

How to put a Next.js app online

· 4 min read

In short

To put a Next.js app online, check that package.json has build and start scripts, do not hardcode the port, and upload the code without the node_modules and .next folders. Netrun installs the dependencies, runs the build, starts the app and gives you an HTTPS link. If there is no server side, the site can be built as a static export (output: 'export') and served as a set of ready-made files.

  • In next start mode, Next.js reads the port from the PORT environment variable by default.
  • A Next.js site with no server-side rendering and no API routes can be built into static files with output: 'export' in next.config.
  • Environment variables meant for the browser are named with the NEXT_PUBLIC_ prefix in Next.js.
  • The node_modules and .next folders do not need uploading: Netrun installs dependencies and builds the project from package.json itself.
  • On the Netrun Free plan a web app sleeps without visitors and wakes on the first request.

Normally, to put a Next.js app online you have to rent a server, install Node.js on it, build the project with npm run build, run it as a long-lived process, put nginx next to it, get an SSL certificate and make sure everything comes back up after a reboot. For a pet project or a first site that is a lot of manual fiddling.

Netrun takes the infrastructure off your hands: you upload the app code, and we handle the build, launch, restarts, domain and HTTPS. Here is how to get your Next.js online in a few minutes.

  1. Check your package.json#

    Make sure package.json has build and start scripts — usually next build and next start. Netrun uses them to figure out how to build and run the app. If you created the project with create-next-app, these scripts are already there.

  2. Do not set the port to a fixed number#

    If your app has a server side — server-side rendering (SSR) or API routes in the app or pages folder — it runs through next start and needs to listen on a port from an environment variable. Next.js reads the port from the PORT variable by default, so you do not need to write it into your code: Netrun passes the right one in for you.

  3. Decide whether you need a server#

    If the site is purely static — no server-side rendering and no API routes — it can be built as a set of ready-made files: add the static export setting to next.config (output: 'export'), and Netrun will serve the result as a plain static site. But if you have API routes or data loaded on the server, keep the normal mode with next start.

  4. Build a ZIP or connect GitHub#

    You can upload the code in two ways: as a ZIP archive or by importing a GitHub repository, including a private one. You do not need to include the node_modules and .next folders — Netrun installs the dependencies and runs the build itself from your package.json, so the archive stays light.

  5. Provide your secrets during setup#

    If the app talks to a database or external services, do not keep API keys, tokens and the connection string in your code. Netrun asks for them when you set up the project and passes them in as environment variables: in Next.js server-side values are available through process.env, while anything that should reach the browser is, by the Next.js rules, named with the NEXT_PUBLIC_ prefix.

  6. Deploy and watch the status#

    Start the deploy — Netrun detects that it is Node.js, installs the dependencies, runs the build and gives you an HTTPS link. Logs and status show up in your dashboard in real time, so if the build trips on something you will see it right away. If the running project fails, it restarts automatically.

That is it: your Next.js app lives online at an HTTPS address, with no rented server and no nginx setup. The Free plan includes one project, and a web app sleeps when idle and wakes on the first request — it only responds a little slower the first time. If the site needs to be ready at all times, with no pauses, the paid plan with always-on running is a good fit, and extra projects are paid for separately. Try Netrun.

Common questions

Why can't the browser see my environment variable?

In Next.js only variables with the NEXT_PUBLIC_ prefix reach the browser, and their values are baked into the code at build time. So after changing such a variable in the Secrets tab, publish the project again. Do not give secret keys this prefix: any visitor can see its values.

Do I need Vercel to run Next.js?

No. Next.js is a regular Node.js app: after next build, next start runs it on any server with Node.js. Vercel is convenient but not required.

Should I use the normal mode or a static export?

If pages are built from ready data and there are no API routes, a static export is simpler: the output is just a set of files. If data loads on the server, or you have API routes or server actions, you need the normal mode with next start.

Why does the Next.js build fail when dev mode works fine?

Often because of TypeScript errors: next build checks types and stops on an error, while dev mode is more forgiving. Run npm run build locally to see the same error, and on Netrun check the build logs in your dashboard — they show up in real time.

Can I connect my own domain to a Next.js site?

Yes, on the Pro plan: custom domains are added in the dashboard, each with HTTPS, as many as you need. On the Free plan the site runs at the link you are given.

Get your own project online

Upload your code, answer a couple of questions and get a working link. There is a free plan

Try Netrun
All blog articles