-
Notifications
You must be signed in to change notification settings - Fork 1
Backend
mhbarshan edited this page Apr 19, 2025
·
1 revision
- Runtime: Node.js
- Framework: Express.js
- Database: MongoDB (Mongoose ODM)
- Authentication: JWT + bcrypt + OTP (email-based)
- Payments: Stripe API
- File Upload: Multer
- Environment Config: dotenv
- Deployment: Render
backend/
βββ controllers/ # Route logic (e.g., userController, productController)
βββ models/ # Mongoose schemas
βββ routes/ # API route definitions
βββ middlewares/ # Auth, error handling, etc.
βββ utils/ # Helper functions (e.g., email sender, OTP generator)
βββ config/ # DB connection, Stripe config
βββ .env # Environment variables
βββ server.js # Entry point
βββ package.json- Users register/login with email and password.
- Passwords are hashed using
bcrypt. - JWT is generated on login and sent to frontend.
- Admin-only APIs are protected via middleware.
- OTP verification is used for added security or password reset.
Admins can:
- Add, update, or delete products
- View and process orders
Protected by adminMiddleware.
- Register / Login
- Get Profile
- Update Profile
- OTP verification
- JWT Authentication
- CRUD for products
- Reviews system
- Category/tags/filters
- Create order
- View order history
- Stripe payment integration
-
POST /create-checkout-sessionβ Stripe checkout - Webhook listens for payment success
-
authMiddlewareβ verifies JWT -
adminMiddlewareβ checks admin role -
multerβ upload image management
Base URL:
http://localhost:5000/apiExample Endpoints:
POST /api/users/register
POST /api/users/login
GET /api/users/profile
POST /api/products
GET /api/products/:id
POST /api/orders
POST /api/payments/checkout- Clone the repo:
git clone https://github.com/Learnathon-By-Geeky-Solutions/codeclusters
cd codeclusters/backend- Install dependencies:
npm install- Create
.envfile:
PORT = your_port
MONGODB_URI ="your mongoDb uri"
JWT_SECRET = "Provide_secret"
EMAIL_USER = "example@mail.com"
EMAIL_PASS = "password"
ADMIN_EMAIL = "example@mail.com"
ADMIN_PASSWORD = "password"
STRIPE_SECRET_KEY ='your_stripe_secret_key'- Start the server:
npm run devnpm run server # Run with nodemon
npm start # Run in productionMake sure to:
- Set up environment variables in your hosting platform
- Use
buildfolder from frontend inserver.jsfor production - Add a health check route (e.g.
/api/health)
- Keep tokens/keys in
.env, never push them. - Use try-catch and async/await for clean error handling.
- Keep controller logic modular and small.
- Modularize routes and keep them RESTful.
PORT = your_port
MONGODB_URI ="your mongoDb uri"
JWT_SECRET = "Provide_secret"
EMAIL_USER = "example@mail.com"
EMAIL_PASS = "password"
ADMIN_EMAIL = "example@mail.com"
ADMIN_PASSWORD = "password"
STRIPE_SECRET_KEY ='your_stripe_secret_key'