A full-stack application for managing contractor purchase orders, jobs, operations, and work tracking.
Contractor PO System/
├── frontend/ # Frontend HTML/CSS/JS files
│ ├── index.html
│ ├── home.html
│ ├── add-ops.html
│ ├── add-new-ops.html
│ ├── work-done.html
│ ├── styles.css
│ └── api.js # API client for backend communication
│
└── backend/ # Node.js/Express backend
├── server.js # Main server file
├── models/ # MongoDB models
│ ├── User.js
│ ├── Job.js
│ ├── Operation.js
│ └── JobOperation.js
└── routes/ # API routes
├── auth.js
├── jobs.js
├── operations.js
└── work.js
- Node.js (v14 or higher)
- MongoDB (local installation or MongoDB Atlas)
- npm or yarn
-
Navigate to the backend directory:
cd backend -
Install dependencies:
npm install
-
Create a
.envfile in the backend directory:PORT=3000 MONGODB_URI=mongodb://localhost:27017/contractor-po-system JWT_SECRET=your-secret-key-change-this-in-production NODE_ENV=development
For MongoDB Atlas (cloud):
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/contractor-po-system
-
Start MongoDB (if using local installation):
- Windows: Make sure MongoDB service is running
- Mac/Linux:
mongodorbrew services start mongodb-community
-
Start the backend server:
npm start
Or for development with auto-reload:
npm run dev
The server will run on
http://localhost:3000
The frontend is static HTML/CSS/JS files. You can:
-
Option A: Use a simple HTTP server (recommended for development):
cd frontend # Using Python python -m http.server 8000 # Or using Node.js http-server npx http-server -p 8000
-
Option B: Open directly in browser (may have CORS issues):
- Simply open
index.htmlin your browser - Note: You may need to configure CORS in the backend for this to work
- Simply open
-
Access the application at
http://localhost:8000
-
Create a user account:
- You can use the API directly or create a simple script:
curl -X POST http://localhost:3000/api/auth/register \ -H "Content-Type: application/json" \ -d '{"userId":"admin","passkey":"password123","name":"Admin","role":"admin"}'
-
Login using the credentials you created.
POST /api/auth/login- Login with userId and passkeyPOST /api/auth/register- Register new user
GET /api/jobs- Get all jobsGET /api/jobs/search/:jobNumber- Search job by numberGET /api/jobs/:id- Get job by IDPOST /api/jobs- Create new jobPOST /api/jobs/:jobId/operations- Add operations to job
GET /api/operations- Get all operations (optional ?search=query)GET /api/operations/:id- Get operation by IDPOST /api/operations- Create new operationPUT /api/operations/:id- Update operationDELETE /api/operations/:id- Delete operation
GET /api/work/pending/:contractor/:jobNumber- Get pending operationsPOST /api/work/update- Update work done
- User Authentication: Login system with JWT tokens
- Job Management: Create and search jobs
- Operations Management: Create and manage standard operations
- Job Operations: Add operations to specific jobs
- Work Tracking: Track work done by contractors for each job
- Real-time Updates: Frontend communicates with MongoDB through REST API
- Frontend: HTML5, CSS3, JavaScript (ES6 Modules)
- Backend: Node.js, Express.js
- Database: MongoDB with Mongoose ODM
- Authentication: JWT (JSON Web Tokens), bcryptjs
- The frontend uses ES6 modules for API communication
- CORS is enabled for development (configure for production)
- JWT tokens are stored in localStorage
- MongoDB connection string can be configured via environment variables
-
MongoDB Connection Error:
- Ensure MongoDB is running
- Check the MONGODB_URI in
.envfile - Verify network connectivity for MongoDB Atlas
-
CORS Errors:
- Make sure backend is running on port 3000
- Check that frontend is accessing the correct API URL in
api.js
-
Port Already in Use:
- Change PORT in
.envfile - Or stop the process using the port
- Change PORT in
ISC