A full-stack template with Next.js frontend and Express backend.
client/: Next.js frontend with TypeScript and Tailwind CSSserver/: Express.js backend
# Install dependencies for the root, client, and server
npm run install:all
# Run both client and server in development mode
npm run devcd client
npm install
npm run devcd server
npm install
npm run devThe root package.json includes several useful scripts:
npm run dev- Run both client and server in development modenpm run install:all- Install dependencies for root, client, and servernpm run client- Run only the clientnpm run server- Run only the servernpm run build- Build the client for productionnpm run start- Start both client and server in production mode
- Next.js with TypeScript and Tailwind CSS
- API service with Axios for frontend
- Express backend with organized folder structure
- Database-agnostic approach - integrate any database you prefer
- Environment configuration with .env files
- Development setup with Nodemon
- Concurrently for running both services
This template includes a ready-to-use API integration between the client and server:
- The client's API service (
client/src/services/api.js) is pre-configured to connect to the Express backend - Environment variables control the API URL for easy deployment to different environments
- Authentication tokens are automatically included in requests through Axios interceptors
- Error handling is built-in with proper responses
Extending the API with your own endpoints is straightforward:
-
Create a Controller: Add your business logic in a new file in
server/controllers/// Example: server/controllers/productController.js export const getAllProducts = async (req, res) => { // Your logic here res.json({ products: [] }); };
-
Define Routes: Create a routes file in
server/routes/// Example: server/routes/productRoutes.js import express from 'express'; import { getAllProducts } from '../controllers/productController.js'; const router = express.Router(); router.get('/', getAllProducts); export default router;
-
Register Routes: Add your routes in
server/server.jsimport productRoutes from './routes/productRoutes.js'; // ... app.use('/api/products', productRoutes);
-
Create Client Service: Add a service in the client to consume your API
// Example: client/src/services/api.js export const productService = { getProducts: async () => { const response = await api.get('/products'); return response.data; } };
Now your new endpoint is ready to use throughout your application!
This template includes a complete authentication system example:
-
Backend API Endpoints:
POST /api/auth/register- Register a new userPOST /api/auth/login- Login with email and password
-
Frontend Integration:
- The homepage includes a login form example
- Authentication service with token management
- Axios interceptors for adding auth tokens to requests
-
Token-based Authentication:
- JWT (JSON Web Token) for secure authentication
- Token expiration handling
- Protected routes on the backend
See individual README files in each directory for more detailed information.