Deploying Next.js App on Netlify in 2025: The Complete Step-by-Step Guide for Beginners to Pros

Next.js
Netlify
deployment
free hosting
deploy
In 2025, deploying a Next.js app will be more powerful and easier than ever, especially using Netlify, a developer-friendly platform that supports serverless functions, edge middleware, custom domains, and continuous deployment. This step-by-step guide walks you through basic to advanced methods to deploy your Next.js application on Netlify. Whether youβre building a static blog, a dynamic SSR app, or a full-stack site, this guide covers it all.
npm install --save-dev @netlify/next
- β‘ Fast Global CDN
- π§ Built-in CI/CD
- π Serverless & Edge Function Support
- π HTTPS by Default
- π Instant Rollbacks
- π¦ Easy Git Integration
Basic Setup: Next.js App
1npx create-next-app@latest nextjs-netlify-demo
2cd nextjs-netlify-demo
3npm run dev
Now, your app runs on. http://localhost:3000.
Step-by-Step Deployment Methods
Method 1: Deploy via Netlify Git Integration (Recommended for Beginners)
β Prerequisites:
- GitHub account
- Netlify account
π Steps:
- Push Your Code to GitHub
1git init
2git add .
3git commit -m "Initial commit"
4git remote add origin https://github.com/yourusername/your-repo.git
5git push -u origin main
- Log in to Netlify
Go to Netlify Dashboard β Click βAdd New Siteβ β Import from Git - Connect Your GitHub Repository
Select your Next.js repo β Click βDeploy Siteβ - Build Settings
- Build command: npm run build
- Publish directory: .next
- Set Environment Variables (Optional)
If your app uses .env, add variables in Netlify β Site Settings β Environment variables.
Method 2: Using Netlify CLI (Advanced Manual Deployment)
π Install CLI:
1npm install netlify-cli -g
2netlify login
π Prepare Static Export (only for SSG apps):
1npm run build
2npm run export
This generates a /out folder with static files.
π Deploy:
1netlify deploy --dir=out
netlify deploy --dir=out
1netlify deploy --prod --dir=out
Method 3: SSR or API Routes? Use Netlify Adapter + Edge Functions.
If you are using SSR, dynamic routes, or API endpoints:
- Install the adapter:
1npm install --save-dev @netlify/next
- Add the Netlify plugin in next.config.js:
1const { withNetlify } = require('@netlify/next');
2module.exports = withNetlify({
3 // your Next.js config
4});
- Add build script:
1"scripts": {
2 "build": "next build && netlify build"
3}
- Deploy via GitHub or CLI as before.
Use Environment Variables (Securely)
Go to Site Settings β Environment Variables in Netlify.
1NEXT_PUBLIC_API_KEY=your_key
2DATABASE_URL=your_url
Netlify will inject them automatically during the build process.
Optimize SEO for Next.js on Netlify
- Use next/head for meta tags
- Add sitemap and robots.txt
- Enable incremental static regeneration (ISR) where possible
- Use Open Graph Tags and Twitter Cards
Example:
1import Head from 'next/head';
2
3export default function Home() {
4 return (
5 <>
6 <Head>
7 <title>My Next.js Site</title>
8 <meta name="description" content="Deployed on Netlify" />
9 <meta property="og:title" content="My Next.js Site" />
10 <meta property="og:description" content="Built with Next.js & deployed via Netlify" />
11 <meta property="og:image" content="/banner.png" />
12 <meta name="twitter:card" content="summary_large_image" />
13 </Head>
14 </>
15 );
16}
Troubleshooting Common Issues
Issue | Solution |
---|---|
404 on dynamic routes | Use Netlify Functions or adapt SSG/ISR |
Environment variables not loading | Ensure they are added in Netlify settings |
SSR routes not working | Use Netlify adapter |
Build fails | Ensure next build passes locally |
Advanced Tips
- β Enable Netlify Analytics
- π Use Build Hooks for automation
- π§ͺ A/B test via Netlify Split Testing
- π‘ Use Edge Middleware for redirects/auth
- πͺ Integrate GitHub Actions for CI/CD
Vercel vs Netlify (2025)
Feature | Netlify | Vercel |
---|---|---|
Free Tier | Generous | Generous |
CI/CD | Built-in | Built-in |
SSR Support | With adapter | Native |
Edge Functions | Supported | Better optimized |
Analytics | Native (paid) | Native (paid) |
GitHub Actions CI/CD Workflow for Netlify Deployment
Step 1: Prerequisites
- Your Next.js app is hosted on GitHub
- Your app is already deployed to Netlify (either via GitHub or manually)
- You have a Netlify Personal Access Token and Site ID
Step 2: Generate Netlify Access Token
- Go to https://app.netlify.com/user/applications
- Scroll to "Personal Access Tokens."
- Generate a new token (copy it safely)
Step 3: Get Site ID
- Visit your site in Netlify dashboard β Settings β General β Site Information.
- Copy the Site ID
Step 4: Add Secrets to GitHub Repo
Go to your GitHub repo β Settings β Secrets β Actions β Add the following secrets:
Name | Value |
---|---|
NETLIFY_AUTH_TOKEN | Your Netlify personal access token |
NETLIFY_SITE_ID | Your Netlify site ID |
Step 5: Create GitHub Actions Workflow
Create a file in your repo:
π .github/workflows/deploy.yml
1name: Deploy Next.js to Netlify
2
3on:
4 push:
5 branches:
6 - main # or your default branch
7
8jobs:
9 build-deploy:
10 runs-on: ubuntu-latest
11
12 steps:
13 - name: Checkout Repository
14 uses: actions/checkout@v4
15
16 - name: Setup Node.js
17 uses: actions/setup-node@v4
18 with:
19 node-version: 18
20
21 - name: Install Dependencies
22 run: npm install
23
24 - name: Build Project
25 run: npm run build
26
27 - name: Install Netlify CLI
28 run: npm install netlify-cli -g
29
30 - name: Deploy to Netlify
31 run: netlify deploy --dir=.next --prod --auth ${{ secrets.NETLIFY_AUTH_TOKEN }} --site ${{ secrets.NETLIFY_SITE_ID }}
π‘ Notes:
- If you're using Static Export, change --dir=.next to --dir=out and ensure npm run export It is used after the build.
- Adjust node-version If your project uses a different Node.js version.
β Result:
Every time you push to main GitHub Actions will:
- Install your dependencies
- Build your Next.js app
- Deploy it to your Netlify site β automatically.
Conclusion
Netlify is one of the best platforms to deploy your Next.js applicationsβfrom simple static websites to fully dynamic apps with SSR and edge logic. With proper setup and Netlify tools, your site will be fast, scalable, and ready for production.