Deploy Next.js websites
To run your website on a server or other platform, you need to deploy it. Next.js makes this process straightforward with built-in support for various deployment platforms.
To deploy your website check out the deployment documentation .
The next step after development is deployment. This creates a production-ready version of your application that can later be accessed by users over the internet.
Create a standalone version of your application
I recommend creating the Next.js application as a standalone version. This has the following advantages:
- Independent deployment: The application contains all necessary dependencies and build artifacts, allowing it to run without relying on a global Next.js installation or external Node modules.
- Simplified Docker integration: The standalone folder can be copied directly into a container, reducing setup steps and minimizing image size.
- Optimized for production: Only the files required for server execution are included, improving startup time and reducing potential conflicts.
- Consistent environment: Ensures that the application behaves the same on any server or container, avoiding issues with differing global packages or Node versions.
To generate a standalone version of your application, edit the next.config.js
file in your project root and add the following configuration:
import type { NextConfig } from "next";
const nextConfig: NextConfig = {
output: "standalone" // <-- Add this line to enable standalone output
};
export default nextConfig;
Generate a production build
Finally you can generate a production build of your application. To do this, run the following command in your projects terminal:
npm run build
This compiles your application into optimized JavaScript and CSS bundles. It also pre-renders pages according to your configuration (Static Generation or Server-Side Rendering). In general this command optimizes your application for production by minifying code, splitting bundles, and enabling caching strategies.
Next steps
In my opinion, the best way to host the production build right now is to start it in a Docker container. I’ll go into more detail about that here.
Alternatively, there is also the option of hosting the website with the Node Process Manager. You can find a good guide to hosting with PM2 here .