agentleFS
ElvitaStudioElvitaStudio/vps-deploy-skills/skills/nextjs-deploy/SKILL.md

nextjs-deploy

Skill1 starsChanged 5 months agoMITView on GitHub

Deploy Next.js 14+ App Router applications to a VPS using PM2 as the process manager. Use this skill when: the user wants to deploy, redeploy, or troubleshoot a Next.js app on a remote VPS. Next.js reads .env.local at build time for NEXT_PUBLIC_* vars. Always rebuild after changing .env.local. Server-side vars (not prefixed with NEXT_PUBLIC_) are read at runtime — no rebuild needed, but PM2 restart is required. Each app must use a unique port. Keep a port registry: Check before…

  • Reads credentials
  • Deletes or force-pushes
  • Installs packages

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Check before assigning a new port:

    line 114

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Next.js Deploy Skill

Deploy Next.js 14+ App Router applications to a VPS using PM2 as the process manager.

Use this skill when: the user wants to deploy, redeploy, or troubleshoot a Next.js app on a remote VPS.


Stack assumptions

  • Next.js 14+ with App Router
  • Node.js 18+
  • PM2 installed globally (npm i -g pm2)
  • Files uploaded via SFTP (e.g. Transmit, rsync, scp)
  • App lives at /root/<project>/frontend or /var/www/<project>

Standard deploy flow

1. Upload files to server

Upload the entire project directory via SFTP excluding node_modules and .next.

2. Install dependencies & build on server

cd /root/<project>/frontend
npm install
npm run build

3. Restart PM2 process

pm2 restart <process-name>
# or if starting for the first time:
pm2 start node_modules/.bin/next --name <process-name> -- start -p <PORT>
pm2 save

4. Verify

pm2 status
pm2 logs <process-name> --lines 20
curl http://localhost:<PORT>

Environment variables

Next.js reads .env.local at build time for NEXT_PUBLIC_* vars.
Always rebuild after changing .env.local.

# /root/<project>/frontend/.env.local
NEXT_PUBLIC_API_URL=https://api.yourdomain.com

Server-side vars (not prefixed with NEXT_PUBLIC_) are read at runtime — no rebuild needed, but PM2 restart is required.


PM2 start command variants

# Standard (uses package.json start script)
pm2 start npm --name myapp -- start

# With explicit port
pm2 start node_modules/.bin/next --name myapp -- start -p 3010

# From ecosystem file (recommended for multiple apps)
pm2 start ecosystem.config.js --only myapp

Common issues & fixes

Port already in use

pm2 list                          # find what's on the port
pm2 delete <conflicting-process>  # or change port
lsof -i :<PORT>                   # double-check

Build fails: "out of memory"

NODE_OPTIONS=--max-old-space-size=512 npm run build

App shows old version after deploy

pm2 stop <name>
rm -rf .next
npm run build
pm2 start <name>

.env.local changes not reflected

Always rebuild: npm run build && pm2 restart <name>


Multiple Next.js apps on one server

Each app must use a unique port. Keep a port registry:

3005 - project-alpha (pm2 id: 0)
3006 - project-beta-admin (pm2 id: 1)
3010 - project-gamma (pm2 id: 2)

Check before assigning a new port:

pm2 list
ss -tlnp | grep LISTEN

🇷🇺 На русском

Используй этот скилл когда нужно задеплоить, передеплоить или починить Next.js приложение на VPS.

Стандартный флоу деплоя:

  1. Загрузи файлы через SFTP (без node_modules и .next)
  2. На сервере: npm install && npm run build
  3. Перезапусти PM2: pm2 restart <имя-процесса>
  4. Проверь: pm2 logs <имя> --lines 20

Частые проблемы:

  • Порт занят → pm2 list + смени порт или убей конфликтующий процесс
  • Старая версия показывается → удали .next, пересобери
  • .env.local не применяется → обязательно пересобери после изменений

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.