In this lesson you will
- Read the production domain from an environment variable and know when it is fixed
- Generate a sitemap with hreflang alternates for both languages
- Build a standalone folder and run it with node server.js
- Check a deployment with curl before you tell anyone it is live
Step 1: the domain comes from the environment
In lessons 5 and 6 the domain was written into the code. A real project runs in several places, your laptop, a preview server and production, so read it from an environment variable instead. lib/site.ts exports SITE_URL with a local fallback, and the layout, sitemap and robots file all import it. Variables without the NEXT_PUBLIC_ prefix stay on the server; with the prefix, Next.js copies the value into the JavaScript sent to browsers, so never put a secret in a NEXT_PUBLIC_ variable.
Locally you can keep values in .env.local, which create-next-app already lists in .gitignore, so it never reaches Git. On the server you set them in the environment of the build and of the process. For the build log in this lesson we ran npm run build with SITE_URL set to https://souq-guide.example.
export const SITE_URL = process.env.SITE_URL ?? "http://localhost:3000";import { SITE_URL } from "@/lib/site";
return {
metadataBase: new URL(SITE_URL),
title: { template: `%s | ${dict.site}`, default: dict.site },
alternates: { languages: { en: "/en", ar: "/ar", "x-default": "/en" } },
};import type { MetadataRoute } from "next";
import { SITE_URL } from "@/lib/site";
export default function robots(): MetadataRoute.Robots {
return {
rules: { userAgent: "*", allow: "/", disallow: "/api/" },
sitemap: `${SITE_URL}/sitemap.xml`,
};
}User-Agent: *
Allow: /
Disallow: /api/
Sitemap: https://souq-guide.example/sitemap.xmlSign in free to read the full lesson
You are reading the free preview. Create a free account (it takes one minute, no password) to unlock the rest of this lesson and track your progress.
Unlocks after sign-in:
- 4 more sections with live code examples
- Common mistakes to avoid
- Hands-on coding exercise with automatic checks
- Practice quiz and the graded lesson test
Free forever. No card, no paywall.
Questions people ask
Is Vercel the only way to host Next.js?
No. The official docs say a Node.js server supports every feature, and any VPS or container host can run one, as in this project. Vercel, Netlify, Cloudflare and others add Git deploys and a CDN, through their own builds or adapters.
How much does it cost to host a small Next.js site?
Many platforms have a free tier that is enough for a personal or small business site, and a small VPS costs a few dollars a month. Prices and limits change, so check the current plan pages before you choose.
What is the difference between next start and node server.js?
next start runs the production server from a full project with node_modules. node server.js is the minimal server inside .next/standalone, made by output: "standalone", which needs only that folder plus the copied static files.
Can I host a Next.js site on shared cPanel hosting?
Only if the plan can run a Node.js application, which some do through a Node.js app manager. If it serves only PHP and static files, you can upload a static export instead, but route handlers, proxy.ts and streaming will not work.
What should I learn after this Next.js course?
Pick one real project and finish it: a site for a local business, a menu or a booking page. Then learn a database with an ORM, authentication and Server Actions for forms, which build directly on the server components and route handlers from this course.
Sources
Facts in this lesson were checked against these official pages on 26 November 2026.
- Next.js docs: Deploying
- Next.js docs: output (standalone)
- Next.js docs: Environment variables
- Next.js docs: Self-hosting
Code examples stay in English and run in a sandbox on your device. If you spot a mistake, tell us through the contact page.