Frontend Development

Next.js Mastery: Elevating Web Development Across Stacks

By the Domain India teamPublished 8 min read
Knowledge base article
Contents (8 sections)

Next.js is a React framework for building websites and web applications. It adds what React alone leaves to you: routing, server rendering, static generation, data fetching, image optimisation and a build system. This guide explains what Next.js is, its core features, how it fits with the stacks you may already use (MERN, headless CMS, Jamstack and PHP back ends), and where to run it on Domain India.

Key takeaways

Next.js turns React into a full framework. New projects use the App Router, where components render on the server by default, pages can be static, dynamic or regenerated on a schedule, and route handlers and Server Actions replace much of a separate API. It works as the front end of almost any stack: in place of plain React in MERN, in front of a headless CMS, as a static Jamstack site, or on top of a PHP or Python API. On Domain India, upload a static export to shared hosting, or run a server-rendered app on the App Platform or a VPS.

1. What Next.js adds to React

React draws the user interface. A real website also needs URLs, SEO-friendly HTML, data loading, images and a production build. Next.js provides these with sensible defaults:

File-based routing
Folders in app/ become URLs. app/blog/[slug]/page.tsx serves every blog post.
Server rendering
Pages arrive as HTML, which is faster to display and easier for search engines to read.
Static generation
Pages that don't change per visitor are built once and served as files.
Route handlers
app/api/.../route.ts files answer API requests inside the same project.
Images and fonts
next/image resizes and lazy-loads images; next/font self-hosts fonts.
Styling
CSS Modules and global CSS work out of the box; Tailwind CSS and Sass are common additions.

Create a project with:

bash
npx create-next-app@latest my-app
cd my-app
npm run dev        # development server on http://localhost:3000

Check the Next.js documentation for the Node.js version the current release needs; use a Node.js LTS release.

2. Rendering: static, dynamic and in between

ModeWhen the HTML is madeGood for
StaticAt build timeMarketing pages, blogs, documentation
Dynamic (server-side)On every requestDashboards, personalised pages, search results
Incremental regenerationAt build, then refreshed after a set time or on demandProduct catalogues, news that changes often
StreamingSent in parts as data arrivesPages with one slow section

In the App Router, a page is static unless it reads something that differs per request, such as cookies or uncached data. You can mix modes: a static product page with a dynamic stock count is normal. Newer releases add finer caching controls, so read the caching section of the documentation for the version you install.

3. Server Components and Server Actions

Server Components run only on the server. They can query a database or call an API directly, and their code never reaches the browser, which keeps pages light. Add "use client" at the top of a file only when a component needs state, effects or browser events.

Server Actions are server functions you call from a form or button, which removes much of the fetch-and-API boilerplate for simple changes:

tsx
// app/contact/page.tsx
async function send(formData: FormData) {
  "use server";
  const email = String(formData.get("email") ?? "");
  // validate, then save or send
}

export default function Contact() {
  return (
    <form action={send}>
      <input name="email" type="email" required />
      <button type="submit">Send</button>
    </form>
  );
}

Treat every Server Action like a public API endpoint: validate the input and check that the user is allowed to act. For the App Router in depth, read Next.js App Router modern patterns.

4. Next.js across stacks

StackWhere Next.js fitsWhat it replaces or adds
MERNThe React front end, plus server renderingPlain React; some Express routes move into route handlers
MEANAn alternative front end to AngularAngular, if the team prefers React
Headless CMSThe website in front of WordPress, Strapi or a hosted CMSThe CMS theme layer
JamstackA static site built at deploy timeA static site generator
PHP or Python back endThe front end calling a Laravel, Django or FastAPI APIServer-rendered PHP templates
Full stackPages, API and database access in one projectA separate back-end service
  • MERN and MEAN: keep Express or NestJS for a large API, background jobs or WebSockets, and let Next.js serve the pages. For small apps, route handlers and an ORM such as Prisma can replace the separate server. See Prisma with Next.js.
  • Headless CMS: editors keep the CMS; Next.js fetches content through its API and builds fast pages. Regeneration updates a page when content changes without a full rebuild. See Strapi on a VPS.
  • Jamstack: set output: 'export' and the build produces plain HTML, CSS and JavaScript that any web server can host.
  • LAMP: Next.js does not run inside Apache and PHP. Either export it as static files served by Apache, or run it as a Node.js app beside your PHP API.

5. Strengths and trade-offs

Good for
  • SEO-friendly HTML without a separate server-rendering setup
  • One project for pages, API routes and data access
  • Mixing static and dynamic pages in the same site
  • A large React ecosystem and active development
Watch out for
  • A learning curve: server and client components, caching rules
  • Fast-moving releases; read the upgrade guide before a major version
  • Server features need a Node.js host, not plain shared hosting
  • Long-running jobs and WebSockets belong in a separate service

6. Best practices

  • Keep secrets on the server. Only variables prefixed NEXT_PUBLIC_ are sent to the browser; never put API keys in them.
  • Default to Server Components. Add client components only where interaction is needed.
  • Use next/image and next/font to avoid slow images and layout shifts.
  • Validate everything in route handlers and Server Actions, and check authorisation on the server, not only in the UI.
  • Cache deliberately. Decide for each page whether it is static, dynamic or regenerated.
  • Keep Next.js updated. Security fixes arrive in patch releases.

7. Running Next.js on Domain India

Which product fits depends on whether your site needs a Node.js server at run time. The full comparison, including Vercel and Cloudflare, is in Next.js hosting: shared vs VPS.

  • Shared hosting (static export): build with output: 'export' on your computer and upload the out/ folder to public_html. You lose server rendering, route handlers, Server Actions, proxy/middleware and built-in image optimisation.
  • App Platform: Node.js apps are detected and built automatically. Your app must listen on the PORT environment variable and bind to 0.0.0.0; next start reads PORT. Pushing to GitHub doesn't deploy by itself: click Deploy Now or use a deploy token in CI. The App Platform does not support WebSockets. See getting started with the App Platform.
  • VPS: a self-managed server where you run next start behind a reverse proxy, with your own database and background workers.

The cards show live Domain India prices, excluding 18% GST.

App Starter
₹100/mo + GST
  • 512 MB RAM per app
  • 1 vCPU
  • 5 GB NVMe SSD
  • PostgreSQL Database
See plan details
VPS Starter
₹552.65/mo + GST
  • 1 vCPU
  • 2 GB DDR4 RAM
  • 64 GB NVMe SSD Storage
  • 2 TB Monthly Bandwidth
See plan details

Frequently asked questions

What is Next.js used for?

Next.js is a React framework for websites and web apps. It adds file-based routing, server rendering, static generation, API route handlers and image optimisation, so it suits marketing sites, blogs, shops, dashboards and SaaS front ends.

Is Next.js a front-end or back-end framework?

Both. It renders React pages on the server and in the browser, and its route handlers and Server Actions can run back-end logic. Large apps often still keep a separate API for heavy or long-running work.

Should I use the App Router or the Pages Router?

Use the App Router for new projects; it is the default in create-next-app and supports Server Components and Server Actions. The Pages Router still works for existing apps.

Can I use Next.js with a PHP or WordPress back end?

Yes. Next.js can fetch data from a Laravel or other PHP API, or from WordPress used as a headless CMS, and render the pages itself.

Can I host Next.js on Domain India shared hosting?

Yes, as a static export: build with output set to export and upload the out folder to public_html. Server rendering, API routes and Server Actions need the App Platform or a VPS.

Does the Domain India App Platform run Next.js?

Yes. The App Platform detects and builds Node.js apps automatically. The app must listen on the PORT environment variable and bind to 0.0.0.0. The App Platform does not support WebSockets.

Ready to deploy your Next.js app? Read Next.js hosting: shared vs VPS, compare the App Platform and VPS plans, or open a ticket if you need help choosing.

Run your Next.js app

Node.js apps are detected and built automatically, with free SSL and your own domain.

See the App Platform

Was this article helpful?

Your answer helps us decide what to improve next.

Still need help? Open a support ticket and our team will reply.

Prefer an app? Add this site to your home screen.Get the app
Next.js Explained: Features and Stacks | Domain India