#
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.
The repository could be located anywhere.
If it is hosted on the same server as you're currently using, (for example,
inside the ~/repos
directory), you can clone it by passing git clone
the
path to the repository.
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.
You can navigate to http://localhost:3000 as long as...
- you're using a virtual machine,
- are working from the host machine, and
- you have port 3000 forwarded
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.