A full-stack e-commerce application with admin panel for managing products and orders.
- Admin Panel: Manage products, categories, and orders
- Shop Frontend: Browse and purchase products
- Authentication: Secure admin login with JWT
- File Uploads: Product image management with security validation
- Order Management: Track and update order status
- Security: Rate limiting, CORS, helmet security headers, input sanitization, and file upload validation
- Database: Automated migrations for schema management
- Logging: Structured logging for debugging and monitoring
- Configuration: Environment variable validation
- Backend: Node.js, Express.js
- Database: SQLite
- Frontend: HTML/CSS/JavaScript
- Authentication: JWT, bcrypt
- File Uploads: Multer
- Node.js (v14 or higher)
- npm or yarn
-
Clone the repository:
git clone <your-repo-url> cd lazy-yoots
-
Install dependencies:
npm install
-
Create environment file:
cp .env.example .env
Edit
.envand set your configuration:PORT: Port to run the server on (default: 3000)NODE_ENV: Environment (development/production)JWT_SECRET: Secret key for JWT tokensALLOWED_ORIGINS: Comma-separated list of allowed origins
-
Start the application:
npm start
Or for development with auto-restart:
npm run dev
- Username: admin
- Password: admin123
Important: Change the default password after first login in production
POST /api/admin/login- Admin loginGET /api/admin/products- Get all products (admin only)POST /api/admin/products- Add new product (admin only)PUT /api/admin/products/:id- Update product (admin only)DELETE /api/admin/products/:id- Delete product (admin only)GET /api/admin/orders- Get all orders (admin only)PUT /api/admin/orders/:id- Update order status (admin only)
GET /api/shop/products- Get all available productsGET /api/shop/products/:id- Get product by IDGET /api/shop/products/category/:category- Get products by categoryGET /api/shop/categories- Get all categoriesPOST /api/shop/orders- Create new order
GET /health- Health check endpoint/uploads/- Static file serving for product images
- Create a new Heroku app
- Connect to your GitHub repository
- Set environment variables in Heroku dashboard
- Deploy the branch
- Create a new Railway project
- Connect to your GitHub repository
- Set environment variables
- Deploy
- Clone the repository on your server
- Install Node.js and dependencies
- Set up environment variables
- Use PM2 to run the application in production:
npm install -g pm2 pm2 start backend/server.js --name "lazy-yoots" pm2 startup pm2 save
Create a .env file in the root directory with the following variables:
# Application Configuration
PORT=3000
NODE_ENV=production
# Security
JWT_SECRET=your-super-secret-jwt-key-here-make-it-long-and-random
ALLOWED_ORIGINS=http://localhost:3000,https://yourdomain.comThe application uses SQLite for simplicity. The database file is created automatically as backend/database.sqlite.
- Rate limiting (100 requests per 15 minutes per IP)
- Helmet security headers
- Input validation and sanitization
- Password hashing with bcrypt
- JWT-based authentication
- CORS configuration
- File upload validation (type, size, extension)
- SQL injection prevention
- XSS prevention through input sanitization
- Environment variable validation
Product images are stored in the backend/uploads/ directory. Make sure this directory has write permissions.
This application has been enhanced with several improvements:
- Automated schema management through migration system
- Version-controlled database changes
- Proper initialization of tables and default data
- Centralized error handling middleware
- Structured logging to files with rotation
- Detailed error information in development mode
- Secure error messages in production
- Validation of required environment variables
- Proper handling of different environments (development, production, test)
- Secure configuration management
- Input sanitization to prevent XSS attacks
- File upload validation (type, size, extension)
- SQL injection prevention
- Enhanced authentication and authorization
- Comprehensive API documentation in
API.md - Clear request/response examples
- Error code explanations
-
Make sure you have installed all dependencies:
npm install
-
Set up your environment variables:
cp .env.example .env # Edit .env with your configuration -
Start the application:
npm start
Or for development:
npm run dev
- Use a strong JWT secret
- Configure ALLOWED_ORIGINS to only include your frontend domains
- Set NODE_ENV to 'production'
- Use a reverse proxy like Nginx
- Implement proper logging
- Regular database backups
- Use PM2 or similar for process management
For support, please open an issue in the repository.