Chapter 10 of 11
Building locally is great — but your goal is to get your app on the internet so real people can use it. Next.js has several deployment options, from completely automated (Vercel) to fully custom (your own server).
ANALOGY
Real-world analogy: A managed warehouse. Deploying to Vercel is like using a fully-managed warehouse vs building your own. With a managed warehouse, you just send your inventory and they handle all the storage, security, temperature control, and shipping. With Vercel, you just push your code and they handle servers, HTTPS, CDN, and scaling.
# Step 1: Install the Vercel CLI
npm install -g vercel
# Step 2: Login to your Vercel account
vercel login
# Step 3: Deploy from your project folder
vercel
# Done! Your site is live at https://your-project.vercel.app
# Every git push to your main branch redeploys automaticallyTIP
Connect GitHub for automatic deployments. The professional workflow: connect your GitHub repo to Vercel at vercel.com. Every time you push code to the main branch, Vercel automatically deploys it. Every pull request also gets a unique preview URL. This is how real teams ship software.
# On your server, after cloning your repo:
npm install
npm run build # Compiles everything
npm run start # Starts production server on port 3000
# Keep it running permanently with PM2 (a process manager)
npm install -g pm2
pm2 start npm --name "nelsonlabs" -- start
pm2 startup # Auto-restart if the server reboots
pm2 saveFROM node:18-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
FROM node:18-alpine AS runner
WORKDIR /app
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json
EXPOSE 3000
CMD ["npm", "start"]const nextConfig = {
output: "export", // Generates static HTML/CSS/JS files in the /out folder
};npm run build
# Creates a /out folder with pure HTML, CSS, and JavaScript
# Upload to: Netlify, GitHub Pages, AWS S3, Cloudflare Pages, or any web host