storieasy-logo

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

dhruvesh borad

Info

28 Jul 2025

|

12 min to read

Deploying NEXT.js App Guide

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

  1. Use next/head for meta tags
  2. Add sitemap and robots.txt
  3. Enable incremental static regeneration (ISR) where possible
  4. 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

IssueSolution
404 on dynamic routesUse Netlify Functions or adapt SSG/ISR
Environment variables not loadingEnsure they are added in Netlify settings
SSR routes not workingUse Netlify adapter
Build failsEnsure 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)

FeatureNetlifyVercel
Free TierGenerousGenerous
CI/CDBuilt-inBuilt-in
SSR SupportWith adapterNative
Edge FunctionsSupportedBetter optimized
AnalyticsNative (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

  1. Go to https://app.netlify.com/user/applications
  2. Scroll to "Personal Access Tokens."
  3. 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:

NameValue
NETLIFY_AUTH_TOKENYour Netlify personal access token
NETLIFY_SITE_IDYour 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:

  1. Install your dependencies
  2. Build your Next.js app
  3. 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.

Newsletter

Subscribe to our newsletter and get our latest updates.

Share with your friends: