Skip to main content
This guide walks you through setting up the SPS School Backend on your machine for local development or connecting it to a hosted MongoDB Atlas cluster.

Prerequisites

Before you begin, make sure the following are installed:
RequirementMinimum versionNotes
Node.js18.xLTS recommended
npm9.xBundled with Node.js
MongoDB6.x (local) or AtlasSee setup options below
Check your installed versions with node -v, npm -v, and mongod --version before continuing.

Installation

1

Clone the repository

git clone https://github.com/praveenarya123/sps-backend.git
cd sps-backend
2

Install dependencies

npm install
This installs all production and development dependencies defined in package.json, including Express, Mongoose, bcryptjs, jsonwebtoken, and nodemon.
3

Configure environment variables

Copy the example environment file and fill in your values:
cp .env.example .env
At minimum, set PORT, MONGODB_URI, and JWT_SECRET. See the environment variables reference for details on each variable.
4

Set up MongoDB

Choose your database setup:
Install MongoDB Community Edition for your operating system.
brew tap mongodb/brew
brew install mongodb-community
brew services start mongodb-community
Once MongoDB is running, set your connection string in .env:
MONGODB_URI=mongodb://localhost:27017/sps-school
MongoDB will create the sps-school database automatically on first write.
5

Start the server

npx nodemon server.js
nodemon watches for file changes and automatically restarts the process. This is the recommended mode during active development.
You can also add a dev script to package.json for convenience:
"scripts": {
  "dev": "nodemon server.js",
  "start": "node server.js"
}
Then run npm run dev.

Verify the server is running

Once the server starts, confirm it is responding correctly by sending a request to the root endpoint:
curl http://localhost:5000/
Expected response:
SPS School Backend Running
You can also open http://localhost:5000/ in your browser and you should see the same message.
The default port is 5000, read from process.env.PORT. If you set a different value in your .env file, use that port instead.

Project structure

The following tree shows the top-level layout of the project:
sps-backend/
├── server.js              # Entry point
├── package.json
├── .env                   # Local config (do not commit)
├── config/
│   └── db.js              # MongoDB connection
├── routes/
│   ├── authRoutes.js
│   ├── teacherRoutes.js
│   ├── studentRoutes.js
│   ├── attendanceRoutes.js
│   ├── assignmentRoutes.js
│   ├── applicationRoutes.js
│   └── financeRoutes.js
├── controllers/
│   ├── authController.js
│   ├── studentController.js
│   ├── teacherController.js
│   ├── attendanceController.js
│   ├── assignmentController.js
│   ├── applicationController.js
│   └── financeController.js
├── middleware/
│   ├── authMiddleware.js
│   └── roleMiddleware.js
└── models/
    ├── User.js
    ├── Student.js
    ├── Teacher.js
    ├── Attendance.js
    ├── Assignment.js
    ├── Submission.js
    ├── Application.js
    └── Fee.js
File / folderPurpose
server.jsApplication entry point. Initializes Express, mounts routes, and starts the HTTP server.
config/db.jsEstablishes the Mongoose connection to MongoDB using MONGODB_URI.
routes/One file per resource. Each file defines the route handlers for that domain area.
controllers/Business logic separated from routing. Called by route handlers.
middleware/Reusable middleware, including JWT authentication checks.
models/Mongoose schema and model definitions.
.envLocal environment configuration. Never commit this file.

Available API routes

The following base paths are mounted in server.js:
Route prefixDescription
GET /Health check — returns "SPS School Backend Running"
/api/authAuthentication (register, login)
/api/teacherTeacher management
/api/studentStudent management
/api/attendanceAttendance tracking
/api/assignmentAssignment management
/api/applicationApplications and admissions
/api/financeFinance and fee management

Next steps

Environment variables

Full reference for all required and optional environment variables.

Authentication

How to authenticate requests using JWT tokens.