This project supports running backend logic through Next.js route handlers (e.g. /app/api/**), allowing full backend functionality without a separate Express server.
Useful for:
- 1-click Vercel deploys
- decide use Next.js server for both frontend and backend
These API routes reuse shared backend logic from the
next-ecommerce-backendpackage — the same logic used in the Express app.
To run the app with Next.js API routes, you must configure environment variables.
📄 See
functions/.env.examplefor full reference and inline comments.
Update the values to match your database, domain, etc.
-
The backend logic is packaged into
next-ecommerce-backend.tgzusingpnpm pack
(you run this manually after making changes to/backend). -
During root
pnpm build, we:- Copy all route files from
functions/api/intoapp/api/ - Copy all frontend files from
frontend/to the root (app/,components/, etc.)
- Copy all route files from
If you make changes to the backend source code (/backend), you must rebuild the backend package to apply them to serverless functions.
Before packing, make sure you've installed backend dependencies:
cd ../backend
pnpm installThen run from the root:
pnpm run pack:backendThis command will:
- 🔨 Build the backend code
- 📦 Create a
.tgzarchive (next-ecommerce-backend.tgz) - 📥 Install it as a local dependency in the root project
🛠️ Required before
next build— otherwise, your updated backend code won’t be included in serverless routes.
To start the app with Next.js API routes:
- Make sure you create a
.envfile in the root and configure it
Run the build command from the root:
pnpm run buildStart the dev server:
pnpm exec next dev