July 12, 2022 . 2 MIN READ
Next.js is a powerful framework built on top of React that helps you build applications quickly. It includes features like image optimization, file-based routing, code splitting, and incremental static generation.
When deploying a Next.js app, you have two main options:
This approach generates all your pages as static HTML files. It provides fast performance since everything is pre-built.
Best for:
Small to medium sites
Projects with fewer pages
Simple blogs or landing pages
This method uses a Node.js server to generate pages dynamically or serve them statically when needed.
Best for:
Large websites (e.g., eCommerce, big blogs)
Thousands of pages
Projects requiring incremental static regeneration
Before you begin, make sure you have:
A GitHub account
Node.js installed locally
A code editor (e.g., Visual Studio Code)
Basic knowledge of JavaScript
Use the following command to create a new app:
Navigate into the project:
Create a new repository on GitHub, then run:
Update your package.json:
Run:
This generates a _static folder with all HTML files.
Add _static to .gitignore:
Then push changes:
Go to your App Platform dashboard
Create a new app from your GitHub repo
Select:
Type: Static Site
Build Command: npm run export
Choose region and enable auto-deploy
Launch the app
Your site will be live with a public URL.
For dynamic rendering and incremental static regeneration:
Modify package.json:
Create a new app in App Platform
Select your GitHub repo
Configure:
Type: Web Service
Build Command: npm run build
Start Command: npm start
Choose a paid plan (e.g., Basic)
Launch the app
Static export is faster but less flexible
Custom server supports dynamic content and scaling
App Platform auto-deploys when you push updates to GitHub
Reference:
https://docs.digitalocean.com/tutorials/app-nextjs-deploy/