A fully functional backend API built with Node.js, Express, and MongoDB.
- Express.js web framework
- MongoDB with Mongoose ODM
- CORS enabled
- Environment variables support
- Request logging with Morgan
- RESTful API structure
- Error handling middleware
CSSE_API/
├── server.js # Entry point
├── package.json # Dependencies and scripts
├── .env # Environment variables
├── .gitignore # Git ignore rules
└── src/
├── models/ # Database models
├── controllers/ # Request handlers
├── routes/ # API routes
└── utils/ # Utility functions
- Install dependencies:
npm install-
Set up MongoDB (choose one):
- Local: Install and start MongoDB (see SETUP.md)
- Cloud: Use MongoDB Atlas and update
.envwith connection string
-
Create a
.envfile:
PORT=3000
MONGODB_URI=mongodb://localhost:27017/csse_api
NODE_ENV=development- Start the server:
npm run devFor detailed setup instructions, see SETUP.md
Development mode (with auto-reload):
npm run devProduction mode:
npm startGET /api/example- Get all examplesGET /api/example/:id- Get example by IDPOST /api/example- Create new examplePUT /api/example/:id- Update exampleDELETE /api/example/:id- Delete example
You can test the API using tools like:
- Postman
- Thunder Client (VS Code extension)
- cURL
- Insomnia
Example cURL command:
curl http://localhost:3000/To add a new feature:
- Create a model in
src/models/ - Create a controller in
src/controllers/ - Create routes in
src/routes/ - Import and use the routes in
server.js
ISC