Back
How to Connect Next.js + Node.js API for a Production-Ready MVP

Photo by Clément H on Unsplash

How to Connect Next.js + Node.js API for a Production-Ready MVP

MT
MVPHub Team
3 min read

How to Connect Next.js + Node.js API for a Production-Ready MVP

Most Next.js MVPs don't need a separate backend — API Routes and Server Actions handle everything. But when you do need a separate Node.js API, here's how to connect them properly.


Do You Actually Need a Separate Backend?

Use Next.js API Routes When:

  • Your backend logic is straightforward CRUD
  • You're deploying to Vercel (serverless API Routes work great)
  • You don't need WebSockets or long-running processes
  • Your team is comfortable with Next.js

Add a Separate Node.js API When:

  • You need WebSockets (real-time features)
  • You have long-running background jobs
  • You need to serve multiple clients (web app, mobile app, third-party API)
  • Your API logic is complex enough to warrant separation
  • You need a persistent server process

Architecture Pattern

Next.js (Frontend + BFF)     Node.js API (Backend)
┌──────────────────┐         ┌──────────────────┐
│ React Components │         │ Express/Fastify   │
│ Server Components│ ──API──→│ Business Logic    │
│ API Routes (BFF) │         │ Database Access   │
│ Server Actions   │         │ Background Jobs   │
└──────────────────┘         └──────────────────┘
    Vercel                    Railway/Fly.io

BFF (Backend for Frontend): Your Next.js API Routes act as a thin proxy, handling auth cookies and forwarding requests to the Node.js API. This keeps auth logic on the frontend server and business logic on the backend.


Communication Patterns

Standard HTTP requests from Next.js Server Components or API Routes to the Node.js API.

tRPC (Type-Safe Alternative)

Share TypeScript types between frontend and backend. Full end-to-end type safety with zero code generation.

GraphQL (Overkill for Most MVPs)

Flexible but adds complexity. Use only if you have many clients with different data needs.


Authentication Between Services

Pattern: Shared JWT or Session

  1. User logs in via Next.js (sets HTTP-only cookie)
  2. Next.js API Route reads cookie, extracts user info
  3. Next.js API Route forwards request to Node.js API with an internal auth header
  4. Node.js API verifies the internal auth header

Never expose the Node.js API directly to the browser. Always go through Next.js as the BFF.


Deployment

ServicePlatformWhy
Next.jsVercelOptimized for Next.js, global edge
Node.js APIRailwayEasy Node.js hosting with databases
DatabaseNeonServerless PostgreSQL

Environment Variables

  • NEXT_PUBLIC_* — Only for client-side values
  • API_URL — Internal Node.js API URL (not exposed to client)
  • API_SECRET — Shared secret for service-to-service auth

Building with Next.js only? Browse Next.js boilerplates on MVPHub.

Node.js architecture: Read Node.js MVP Architecture.


Working products with full source code — live demo, one-time purchase, instant delivery.

Browse the marketplace
GR LIVEecommerce

Groover Multi-Purpose Store

$149

A fully-polished, multi-purpose e-commerce template engineered for brands that need the full feature set on day one — not a minimal starter you outgrow in a month. Groover ships with a live Medusa-backed catalog, category + collection merchandising, search with multi-facet filtering (category, collection, price, sale, stock, sort), product-detail with variant selection + image gallery + stock messaging + related products, Stripe Elements checkout with provider-aware setup panels, account dashboard with guest order lookup and authenticated order history, customer auth with login/register/logout/profile edit, wishlist with guest browser persistence and signed-in customer sync, blog list + detail, store directory, track-order page, branded 404, About/Contact/FAQ/Terms legal shell, GTM-friendly dataLayer wired into PDP/cards/wishlist/cart/checkout/search, locale + RTL foundation with persistent language switcher, PWA installability baseline, theme switching that applies before hydration and persists in both local storage and cookies, header active-route navigation with live mini-cart summary, skip-link / focus accessibility basics, app-level and route-level loading fallbacks, a recoverable error boundary, generated robots.txt and sitemap.xml, shared SEO metadata helpers, and a Playwright / Vitest / Lighthouse test harness. Every copy string lives in a typed content map so rebranding is a find-and-replace pass, not a code rewrite. Deploy it as-is or use it as the most complete starting point you can buy for a serious storefront.

★★★★★0 soldAstro · Medusa
FU LIVEecommerce

Furniture Store

$49

An elegant furniture and home furnishing e-commerce app with a design-forward Next.js storefront for SEO-optimized product pages and server-rendered category browsing. Alternative framework and mobile ports are available on demand. The visual design emphasizes large product imagery, room-based browsing, and material/color variant selection. Built with Radix UI, shadcn/ui, Tailwind CSS, and Framer Motion for a premium feel. Connects to any headless commerce backend — Medusa JS SDK integration is included. Form handling via React Hook Form with Zod validation ensures robust checkout and account flows. Great for furniture brands, interior design shops, or home decor marketplaces.

★★★★★0 soldExpo · Next.js
PE LIVEecommerce

Perfume Store

$49

A luxury-styled perfume and fragrance e-commerce app built for premium brand presentation. The ready-to-buy Next.js storefront features rich product pages with scent profiles, bottle size variants, gift set options, and server-rendered collections. Mobile, backend, and alternative framework ports are available on demand. The design uses shadcn/ui and Tailwind CSS with an elegant, minimalist aesthetic suited for luxury goods. Easy to customize — swap product data, update branding, and deploy. Perfect for perfume brands, fragrance boutiques, or niche scent marketplaces.

★★★★★0 soldMedusa · Expo

Keep reading — popular Tech Stack guides on MVPHub.

All Tech Stack articles

Explore other MVP verticals

MVPHub publishes templates and guides for ecommerce, SaaS, marketplaces, AI apps, booking platforms, subscription stores, directory sites, and more. Here are fresh picks from other verticals.