Prerequisites
Before setting up the backend, ensure you have the following installed:Node.js
Install Node.js (version 18 or higher recommended). The backend uses ES modules and modern JavaScript features.
MongoDB
You’ll need a MongoDB database. You can use:
- MongoDB Atlas (cloud)
- Local MongoDB installation
Installation
Clone and Install Dependencies
- Express - Web framework
- Mongoose - MongoDB object modeling
- @clerk/express - Authentication
- Cloudinary - Image upload management
- Stripe - Payment processing
- Inngest - Event-driven functions
- CORS - Cross-origin resource sharing
The backend uses ES modules (
"type": "module" in package.json), so all imports use the import syntax instead of require.Project Structure
The backend follows a modular architecture:Development Server
Start the Server
src directory and automatically restart the server.
The
dev:all command runs both the main server and Inngest dev server concurrently using the concurrently package.Server Output
When the server starts successfully, you’ll see:Available Scripts
Frompackage.json:
| Script | Command | Description |
|---|---|---|
npm run dev | nodemon src/server.js | Start development server with auto-reload |
npm run inngest | npx inngest-cli@latest dev -u http://localhost:3000/api/inngest | Start Inngest dev server |
npm run dev:all | concurrently "npm run dev" "npm run inngest" | Run both servers simultaneously |
npm run seed:products | node src/seeds/index.js | Seed the database with products |
Seeding the Database
To populate your database with initial product data:- Connect to MongoDB
- Clear existing products
- Insert 15 products across categories:
- Palitos Premium
- Palitos Cocteleros
- Dulces
- Especiales
- Nuevos
API Endpoints
Once running, the API is available athttp://localhost:3000
Core Endpoints
GET /- API health checkGET /api/health- Health status endpointPOST /api/webhooks/clerk- Clerk authentication webhooks/api/inngest- Inngest event endpoint
Resource Endpoints
/api/admin- Admin operations/api/users- User management/api/products- Product catalog/api/cart- Shopping cart/api/orders- Order processing/api/payment- Stripe payments/api/coupons- Discount coupons/api/reviews- Product reviews
Next Steps
Configuration
Set up environment variables and third-party services
Database
Learn about MongoDB models and schemas
Authentication
Configure Clerk authentication and protected routes