# Serve a Next.js App

# Prerequisites

  • Node.js is installed
  • A Next.js app has been written and its source code is in a git repository accessible by the server
  • You are logged in to the server as a non-root user
  • If using a virtual machine, port 3000 is forwarded

# Clone the repository

Use git clone to clone the repository into the ~/apps directory.

git clone ~/repos/my-app ~/apps/my-app

Change into the repository.

cd ~/apps/my-app

Install the project's dependencies.

npm install

Disable Next.js telemetry.

npx next telemetry disable

Build the project.

npm run build

Serve the project.

npm start

By default, the app will be accessible on port 3000.

# Test the Application Server

Open a web browser and navigate to http://[your server's IP address/hostname]:3000. You should see your Next.js app.

This is a simple setup that isn't fault-tolerant or feasible to manage. You may want to manage your Node.js processes using a manager like PM2.