A Node.js backend API server for the Usta Dashboard application, built with Express.js and MongoDB.
- Express.js server with middleware setup
- MongoDB integration with Mongoose
- CORS configuration
- Security headers with Helmet
- Request logging with Morgan
- Environment configuration
- Error handling
- Health check endpoints
- Ticket Management System with CRUD operations
- File upload support with Multer
- Multiple image attachments support
- Node.js (v14 or higher)
- MongoDB (running locally or MongoDB Atlas)
- npm or yarn
-
Clone the repository
-
Install dependencies:
npm install
-
Create a
.envfile based onconfig.env:cp config.env .env
-
Update the
.envfile with your MongoDB connection string and other configurations.
The application uses environment variables for configuration. Key variables include:
PORT: Server port (default: 3000)NODE_ENV: Environment (development/production)MONGODB_URI: MongoDB connection stringJWT_SECRET: Secret key for JWT tokens (if using authentication)CORS_ORIGIN: Allowed CORS origins
npm run devnpm startGET /- Welcome message and API informationGET /health- Health check endpointGET /api- API routes information
POST /api/tickets
Content-Type: multipart/form-data
Fields:
- category (required): String
- description (required): String
- relatedJob (optional): String (job ID)
- submittedBy (required): String (user ID)
- attachments (optional): File[] (multiple files)
GET /api/tickets?page=1&limit=10&status=open&category=bug&submittedBy=userId&sortBy=createdAt&sortOrder=desc
GET /api/tickets/:id
PUT /api/tickets/:id
Content-Type: multipart/form-data
Fields:
- category: String
- description: String
- relatedJob: String
- status: String (open, in-progress, resolved, closed)
- priority: String (low, medium, high, urgent)
- assignedTo: String
- attachments: File[] (new files will replace existing ones, or use "append" to add)
DELETE /api/tickets/:id
POST /api/tickets/:id/comments
Content-Type: application/json
{
"user": "userId",
"comment": "Comment text"
}
GET /api/tickets/user/:userId?page=1&limit=10
interface CreateTicketData {
category: string; // Required
description: string; // Required
relatedJob?: string; // Optional job ID
attachments: File[]; // Multiple files supported
submittedBy: string; // Required user ID
}- Supported file types: Images (jpg, png, gif, webp), PDF, Word docs, text files
- File size limit: 10MB per file
- Maximum files: 5 files per request
- Upload directory:
uploads/tickets/ - Static file serving: Files accessible at
/uploads/tickets/filename
UstaDashboardBackend/
├── config/
│ ├── database.js # MongoDB connection configuration
│ └── multer.js # File upload configuration
├── controllers/
│ └── ticketController.js # Ticket CRUD operations
├── models/
│ └── Ticket.js # Ticket Mongoose model
├── routes/
│ └── ticketRoutes.js # Ticket API routes
├── uploads/
│ └── tickets/ # Uploaded files directory
├── server.js # Main server file
├── package.json # Project dependencies and scripts
├── config.env # Environment variables template
├── .gitignore # Git ignore rules
└── README.md # Project documentation
curl -X POST http://localhost:3000/api/tickets \
-F "category=bug" \
-F "description=Application crashes on login" \
-F "submittedBy=user123" \
-F "relatedJob=job456" \
-F "attachments=@/path/to/screenshot1.png" \
-F "attachments=@/path/to/logfile.txt"curl "http://localhost:3000/api/tickets?page=1&limit=5&status=open"curl -X POST http://localhost:3000/api/tickets/ticketId/comments \
-H "Content-Type: application/json" \
-d '{"user": "user123", "comment": "This issue has been reproduced"}'The project uses nodemon for development, which automatically restarts the server when files change.
- Fork the repository
- Create a feature branch
- Make your changes
- Test your changes
- Submit a pull request
ISC