Backend server for the Virtual Physics Lab application, providing authentication, user management, and progress tracking services.
- Production: https://vlab-backend.vercel.app
- Health Check: https://vlab-backend.vercel.app/api/health
- Runtime: Node.js serverless functions
- Database: MongoDB Atlas
- Authentication: JWT tokens with bcrypt hashing
- Deployment: Vercel serverless functions
- CORS: Configured for cross-origin requests
- Install dependencies:
cd backend
npm install- Set up environment variables:
Copy
.env.exampleto.envand update the values:
cp .env.example .env-
Start MongoDB (make sure MongoDB is installed and running)
-
Install MongoDB Community Edition:
- Windows: Download from https://www.mongodb.com/try/download/community
- macOS:
brew install mongodb-community - Linux: Follow MongoDB official installation guide
-
Start the development server:
npm run devPOST /api/auth/register- Register new userPOST /api/auth/login- Login userGET /api/auth/verify- Verify tokenPOST /api/auth/logout- Logout user
GET /api/users/profile- Get user profilePUT /api/users/profile- Update user profileGET /api/users/stats- Get user statisticsDELETE /api/users/account- Delete user account
POST /api/progress- Save progressGET /api/progress- Get user progressGET /api/progress/stats- Get progress statisticsDELETE /api/progress/:id- Delete progress entry
GET /api/simulations- Get all simulationsGET /api/simulations/:id- Get simulation by IDPOST /api/simulations/initialize- Initialize default simulations (admin)
NODE_ENV- Environment (development/production)PORT- Server port (default: 5000)MONGODB_URI- MongoDB connection stringJWT_SECRET- JWT secret keyFRONTEND_URL- Frontend URL for CORS
- name, email, password (hashed)
- role (student/teacher/admin)
- timestamps, last login
- userId, simulationId, simulationName
- timeSpent, score, parameters, results
- achievements, completedAt
- simulationId, name, description
- category, difficulty, estimatedTime
- parameters, learning objectives
- materials, prerequisites
# Start development server with auto-reload
npm run dev
# Run tests
npm test
# Start production server
npm start