This guide explains how to set up and run the CodeX Backend on your local machine for development or in a production environment.
Before setting up the project, make sure the following software is installed on your system.
| Software | Recommended Version | Required |
|---|---|---|
| Node.js | 22.x LTS or later | ✅ |
| npm | 10.x or later | ✅ |
| MongoDB | 8.x or MongoDB Atlas | ✅ |
| Git | Latest | ✅ |
Check your installed versions:
node -v
npm -v
git --versionMinimum recommended specifications:
- Windows 10/11, Linux, or macOS
- 4 GB RAM (8 GB recommended)
- Internet connection
- MongoDB database (Local or Atlas)
Clone the backend repository using Git.
git clone <repository-url>Move into the project directory.
cd backendInstall all required project dependencies.
npm installThis installs all packages listed in package.json.
- Express.js
- MongoDB (Mongoose)
- JWT Authentication
- bcryptjs
- Nodemailer
- Cloudinary
- Helmet
- Multer
- Morgan
- Compression
- Rate Limiter
Development dependencies include:
- Nodemon
- ESLint
- Prettier
After installation the project structure should look similar to:
backend/
│
├── docs/
├── src/
├── package.json
├── package-lock.json
├── .env
├── .env.example
└── README.md
Create a new environment file.
cp .env.example .envIf you're using Windows PowerShell:
copy .env.example .envOr create the .env file manually.
Populate it using your project configuration.
Example:
PORT=5000
NODE_ENV=development
MONGODB_URI=
ACCESS_TOKEN_SECRET=
ACCESS_TOKEN_EXPIRY=1d
CORS_ORIGIN=http://localhost:5173
CLOUDINARY_CLOUD_NAME=
CLOUDINARY_API_KEY=
CLOUDINARY_API_SECRET=
SMTP_HOST=
SMTP_PORT=
SMTP_USER=
SMTP_PASSWORD=
FROM_NAME=CodeX Club
FROM_EMAIL=
ADMIN_EMAIL=
ADMIN_PASSWORD=
TURNSTILE_SECRET_KEY=
FRONTEND_URL=http://localhost:5173
SERVER_URL=http://localhost:5000Important
Never commit the
.envfile to Git.Only commit
.env.example.
The backend supports both:
- Local MongoDB
- MongoDB Atlas
Install MongoDB Community Edition.
Start MongoDB.
Windows
net start MongoDBLinux
sudo systemctl start mongodUse the connection string:
mongodb://127.0.0.1:27017/codex
- Create a MongoDB Atlas Cluster.
- Create a Database User.
- Whitelist your IP Address.
- Copy the connection string.
Example:
mongodb+srv://username:password@cluster.mongodb.net/codex
Paste it into:
MONGODB_URI=<your-mongodb-uri>Start the development server using Nodemon.
npm run devThis command runs:
nodemon src/server.jsNodemon automatically restarts the server whenever files are modified.
If everything is configured correctly, you should see output similar to:
MongoDB Connected Successfully
Server running on port 5000
To start the application without Nodemon:
npm startThis runs:
node src/server.js| Command | Description |
|---|---|
npm install |
Install project dependencies |
npm run dev |
Start development server with Nodemon |
npm start |
Start production server |
npm run format |
Format project using Prettier |
npm test |
Placeholder test script |
Once the server starts successfully, open your browser or API client.
Health Check Endpoint
GET /api/v1/healthcheckExample:
http://localhost:5000/api/v1/healthcheck
A successful response confirms that:
- Express server is running
- MongoDB connection is established
- Routes are loaded correctly
Typical development workflow:
- Pull the latest changes.
- Install dependencies if required.
- Update your
.envfile. - Start MongoDB.
- Run the development server.
- Test APIs using Postman or another API client.
- Commit your changes.
- Push to the repository.
The backend does not require a build step because it is a Node.js application.
Production deployment generally consists of:
- Clone the repository.
git clone <repository-url>- Install dependencies.
npm install-
Configure environment variables.
-
Start the server.
npm startFor production environments, it is recommended to:
- Use PM2 as the process manager.
- Place the application behind Nginx or another reverse proxy.
- Enable HTTPS using SSL/TLS certificates.
- Store secrets securely.
- Enable regular database backups.
- Configure application logging and monitoring.
Detailed deployment instructions are available in the deployment.md documentation.
Check:
- MongoDB is running.
MONGODB_URIis correct.- Network access is allowed (Atlas).
- Database credentials are valid.
Change the application port in .env.
PORT=5001or terminate the process using the current port.
Verify:
- Cloud Name
- API Key
- API Secret
All Cloudinary credentials must be valid.
Verify:
- SMTP Host
- SMTP Port
- SMTP Username
- SMTP Password
If using Gmail, use an App Password instead of your account password.
Verify:
ACCESS_TOKEN_SECRETexists.- Cookies are enabled.
- The token has not expired.
- The session still exists in the database.
After successfully setting up the backend, continue with the following documentation:
- project-structure.md – Understand the folder organization.
- architecture.md – Learn how the backend is structured internally.
- authentication.md – Understand the authentication and authorization flow.
- database.md – Explore database models and relationships.
- api-reference.md – Complete REST API documentation.