nextjs

Complete deployment guide for nextjs on NStrim

Overview

Next.js is a React framework for production. It provides hybrid static and server rendering, TypeScript support, smart bundling, route pre-fetching, and more with zero configuration.

Before You Start
Make sure you have your dashboard open - you'll need the Git credentials displayed there. This template includes Next.js 15, React 19, Tailwind CSS 4, Turbopack, and next-auth.

Quick Start

1

Create Repository from Template

On your dashboard, go to the Tools & Deployment tab. Click the "New Repository" button, select the Next.js template from the dropdown, enter a repository name and subdomain, then click "Create Repository".

2

Clone Your Repository

git clone https://<git-server>/<username>/<repo-name>.git
cd <repo-name>
3

Install Dependencies

npm install
4

Start Development Server

npm run dev

Open http://localhost:4200 in your browser.

5

Build & Push

npm run build
git add .
git commit -m "Initial setup"
git push origin main
Every push to Git automatically deploys your application. Check your Module Work URL on the dashboard to see your live site.

Local Development with Docker

If you don't have Node.js installed locally, you can use Docker to run Next.js commands.

What is Docker?
Docker creates isolated "containers" with all the software you need (Node.js, npm) without installing them on your computer.

Running Commands with Docker

# Run npm install
docker run --rm -v $(pwd):/app -w /app node:lts-alpine npm install

# Run development server
docker run --rm -v $(pwd):/app -w /app -p 4200:4200 node:lts-alpine npm run dev

# Build for production
docker run --rm -v $(pwd):/app -w /app node:lts-alpine npm run build

Project Structure

├── app/                      # App Router (Next.js 13+)
│   ├── layout.js             # Root layout
│   ├── page.js               # Home page
│   ├── api/                  # API routes
│   └── [routes]/             # Dynamic routes
├── public/                   # Static files
├── components/               # React components
├── styles/                   # CSS files
├── next.config.js            # Next.js configuration
├── package.json              # Dependencies
└── Dockerfile                # Docker config
        

Common Tasks

Creating a Page

Create files in app/ directory:

// app/about/page.js
export default function AboutPage() {
  return <h1>About Us</h1>;
}

Creating an API Route

// app/api/users/route.js
export async function GET() {
  return Response.json({ users: [] });
}

export async function POST(request) {
  const data = await request.json();
  return Response.json({ created: data });
}

Server vs Client Components

// Server Component (default) - runs on server
export default async function Page() {
  const data = await fetch('https://api.example.com');
  return <div>{data}</div>;
}

// Client Component - add 'use client' directive
'use client';
import { useState } from 'react';
export default function Counter() {
  const [count, setCount] = useState(0);
  return <button onClick={() => setCount(count + 1)}>{count}</button>;
}

Useful Commands

npm run dev Start dev server with Turbopack
npm run build Create production build
npm start Start production server
npm run lint Run ESLint

Troubleshooting

Hydration mismatch errors

Solution: Ensure server and client render the same content. Use 'use client' for interactive components.

useState not working

Solution: Add 'use client' at the top of your file. Server Components can't use hooks.

Build fails after deployment

Solution: Run npm run build locally first to check for errors before pushing.

Deployment Workflow

Code Change git push npm run build Live!
For more information, visit the official Next.js Documentation.