Important: For NextAPI configurations, you need to copy all variables from
server/.env to web/.env because the API routes run within the Next.js
application.What You’ll Get
- Backend: Next.js API routes
- Runtime: Node.js
- Bundler: Webpack (Next.js default)
- Performance: Standard Node.js performance
- Structure: API routes within Next.js app
Prerequisites
Before starting, ensure you have:Step 1: Project Setup
1.1 Access Your Dashboard
-
Visit the Dashboard
- Go to: https://www.builderbox.ai/bought/main
- Log in with your account credentials
-
Create Your Project
- Click “Create Project” on your dashboard
- Select “NextAPI + Node” as your backend configuration
- Fill out the project configuration form
- Click “Create Project” to generate your boilerplate
-
Install Your Project
- Run the provided installation command:
- Run the provided installation command:
Step 2: Environment Configuration
2.1 Web Environment Variables (Combined)
Createapps/web/.env with ALL environment variables:
Key Difference: Unlike Hono configurations, all environment variables are
in
apps/web/.env because the API routes run within the Next.js application.2.2 CMS Environment Variables
Createapps/cms/.env:
Step 3: Database Setup
3.1 Run Database Commands
Step 4: Start Development
4.1 Start All Services
- Frontend App (Next.js + API routes) on port 3001
- CMS on port 3003
4.2 Individual Services (Optional)
If you prefer to run services separately: Terminal 1 - Frontend + API:Step 5: Verify Setup
5.1 Check Services
- Frontend + API: http://localhost:3001
- CMS: http://localhost:3003
5.2 Test API Endpoints
Project Structure
Key Features
Next.js API Routes Benefits
- Unified Codebase: Frontend and backend in one project
- Type Safety: Full TypeScript support
- Middleware: Next.js middleware support
- Deployment: Easy deployment to Vercel
- Familiarity: Standard Next.js patterns
Node.js Runtime Benefits
- Ecosystem: Full Node.js package ecosystem
- Compatibility: Works with all Node.js libraries
- Stability: Mature and well-tested runtime
- Tooling: Rich development tooling
- Community: Large community support
Development Commands
| Command | Description |
|---|---|
pnpm run dev | Start all services |
pnpm run build | Build for production |
pnpm run dev:web | Frontend + API only |
pnpm run check-types | TypeScript validation |
pnpm run db:push | Update database schema |
pnpm run db:studio | Database management UI |
Environment Variables Management
Important Notes
- Single Environment File: All variables are in
apps/web/.env - API Routes Access: Environment variables are accessible in API routes
- Client Variables: Use
NEXT_PUBLIC_prefix for client-side variables - Security: Never expose sensitive variables to the client
Variable Categories
Troubleshooting
Common Issues
🔥 “Environment variables not found”- Ensure all variables are in
apps/web/.env - Check for typos in variable names
- Restart the development server
- Verify your Supabase connection strings
- Ensure your database is running
- Check environment variables in
apps/web/.env
- Verify Google OAuth configuration
- Check BETTER_AUTH_SECRET is set
- Ensure CORS_ORIGIN is correct
Migration from Hono
If you’re migrating from a Hono setup:-
Copy Environment Variables:
-
Update URLs:
-
Update API Calls:
Next Steps
🎉 Congratulations! Your NextAPI + Node setup is complete. Here’s what you can do next:- Customize the frontend - Edit components in
apps/web/src/components - Add API endpoints - Create new routes in
apps/web/src/app/api - Configure CMS - Add content types in
apps/cms/src/collections - Set up production - Deploy to Vercel for optimal performance
- Add features - Extend with additional integrations