A monorepo template with a React.js frontend and Node.js backend application.
mono-repo-template/
├── frontend/ # React.js frontend application (TypeScript + Vite)
├── backend/ # Node.js backend application (Express)
├── package.json # Root package.json with npm workspaces
└── README.md
- Node.js >= 18.0.0
- npm >= 9.0.0
-
Install all dependencies (for both frontend and backend):
npm install
This will install dependencies for both workspaces automatically.
From the root directory:
npm run devThis will start:
- Frontend: http://localhost:5173 (Vite dev server)
- Backend: http://localhost:3000 (Express server)
The frontend is configured with a proxy that forwards /api/* requests to the backend automatically.
Frontend only:
cd frontend
npm run dev
# or
npm startThe frontend will run on http://localhost:5173 with API proxy to http://localhost:3000
Backend only:
cd backend
npm run dev
# or
npm startThe backend will run on http://localhost:3000
npm run dev- Start both frontend and backend in development modenpm run build- Build the frontend for production (generatesfrontend/dist/)npm run start- Build frontend and start backend server (production mode)npm install:all- Install all dependencies
npm run dev/npm start- Start Vite development server (port 5173)npm run build- Build for production (outputs todist/)npm run preview- Preview production build locallynpm test- Run tests (Vitest)
npm run dev- Start backend with watch mode (port 3000)npm start- Start backend server (port 3000)
The backend provides the following endpoints:
GET /api/health- Health check endpointGET /api- Welcome message
In production, the backend serves the frontend static files as a single service:
- Build the frontend:
npm run build - Start the backend:
npm run start(builds frontend automatically)
Or use the root script:
npm run startThis will:
- Build the frontend (creates
frontend/dist/) - Start the backend server
The backend will:
- Serve API routes at
/api/* - Serve static files from
frontend/dist/ - Serve
index.htmlfor all other routes (SPA routing support)
Single service deployment:
- All traffic goes to:
http://localhost:3000 - Frontend routes:
http://localhost:3000/* - API routes:
http://localhost:3000/api/*
This setup is ideal for platforms like Railway, Render, or Fly.io where you deploy a single service.
- Frontend: Vite dev server on port 5173 (with HMR)
- Backend: Express server on port 3000
- API proxy: Frontend automatically proxies
/api/*to backend
- Single service: Backend on port 3000 serves everything
- Frontend static files: Served from
frontend/dist/ - API: Available at
/api/*on the same server
- Frontend: React 19, TypeScript, Vite
- Backend: Node.js, Express, CORS
- Build Tool: Vite (replaces Create React App)
- Package Management: npm workspaces
ISC