This guide will help you run both the backend and frontend locally.
- Node.js (v14 or higher recommended)
- npm (comes with Node.js)
- MongoDB (local instance or MongoDB Atlas connection string)
- Cloudinary account (for file storage)
cd corrupted-files-api
npm installCreate a .env file in the corrupted-files-api directory with the following variables:
# MongoDB Connection
MONGO_URI=mongodb://localhost:27017/lockbox
# Or use MongoDB Atlas: mongodb+srv://username:password@cluster.mongodb.net/lockbox
# JWT Secret Key (use a strong random string)
JWT_KEY=your-secret-jwt-key-here
# Cloudinary Configuration
CLOUDINARY_CLOUD_NAME=your-cloudinary-cloud-name
CLOUDINARY_ACCESS_KEY=your-cloudinary-api-key
CLOUDINARY_SECRET_ACCESS_KEY=your-cloudinary-secret-key
# Server Port (optional, defaults to 8000)
PORT=8000For development (with auto-reload):
npm run devFor production:
npm startThe backend will run on http://localhost:8000
cd frontend
npm installThe frontend uses /api as the base URL. To proxy API requests to the backend during development, add a proxy field to frontend/package.json:
{
"name": "frontend",
"version": "0.1.0",
"private": true,
"proxy": "http://localhost:8000",
...
}Note: If you don't add the proxy, you'll need to configure CORS on the backend or update the axios baseURL to point to http://localhost:8000/api.
npm startThe frontend will run on http://localhost:3000 and automatically open in your browser.
You'll need two terminal windows/tabs:
cd corrupted-files-api
npm run devcd frontend
npm startIf you want to start both servers quickly, you can use these commands in separate terminals:
Backend:
cd corrupted-files-api && npm run devFrontend:
cd frontend && npm start- MongoDB Connection Error: Make sure MongoDB is running locally or your MongoDB Atlas connection string is correct.
- Port Already in Use: Change the
PORTin your.envfile or kill the process using port 8000. - Missing Environment Variables: Ensure all required variables are set in your
.envfile.
- API Requests Failing:
- Add the
proxyfield tofrontend/package.jsonpointing tohttp://localhost:8000 - Or ensure CORS is enabled on the backend
- Add the
- Port 3000 Already in Use: React will prompt you to use a different port, or you can specify one:
PORT=3001 npm start
If you're not using the proxy and getting CORS errors, you may need to enable CORS in the backend. The backend already has cors as a dev dependency, but you may need to configure it in server.js.
Backend Required:
MONGO_URI- MongoDB connection stringJWT_KEY- Secret key for JWT tokens and sessionsCLOUDINARY_CLOUD_NAME- Your Cloudinary cloud nameCLOUDINARY_ACCESS_KEY- Your Cloudinary API keyCLOUDINARY_SECRET_ACCESS_KEY- Your Cloudinary secret keyPORT- Server port (optional, defaults to 8000)
Frontend:
- No environment variables required for basic setup
Once both servers are running:
- Frontend: http://localhost:3000
- Backend API: http://localhost:8000/api
- WebSocket: ws://localhost:8000 (for file decryption)