Skip to main content

Command Palette

Search for a command to run...

(Day 45) Task : Backend Setup with Node.js, Express & First Working Server :-

Published
5 min read
(Day 45) Task : Backend Setup with Node.js, Express & First Working Server :-
A

DevOps Enthusiast | Python | Chef | Docker | GitHub | Linux | Shell Scripting | CI/CD & Cloud Learner | AWS

Introduction :

After completing Day 1 (planning, project structure, and Git setup), Day 2 was the day where real development started.

The goal of Day 2 was simple but very important:
Set up the backend using Node.js and Express and run the first working server.

This step creates the foundation of the entire system because all future features like authentication, events, and resources will be built on top of this backend.

Why Backend Setup Is Important?

The backend is responsible for:

  • Handling requests from frontend.

  • Connecting to the database.

  • Applying business logic.

  • Securing the system.

  • Managing users, events, and resources

    If the backend foundation is weak, the whole project becomes unstable.

So Day 2 was focused on building a clean and scalable backend base.

Tech Used on Day 2 :-

  • Node.js – JavaScript runtime.

  • Express.js – Backend framework.

  • MongoDB – (Will be connected in upcoming days).

  • Cors & Dotenv – For configuration and security.

Backend Folder Structure

Inside the main project folder:

college-event-system/
 ├── backend/
 └── frontend/

Inside backend/ after Day 2:

backend/
 ├── models/
 ├── routes/
 ├── controllers/
 ├── middleware/
 ├── config/
 ├── server.js
 └── package.json

This structure is industry-style and helps in keeping the project clean and scalable.

Step 1: Initializing Node Project :-

Inside the backend folder, I initialized a Node.js project:

npm init -y

This created the package.json file, which manages:

  • Project info

  • Dependencies

  • Scripts

Step 2: Installing Required Packages :-

I installed the core dependencies:

npm install express mongoose cors dotenv
  • express → For creating APIs.

  • mongoose → For MongoDB (used later).

  • cors → For frontend-backend communication.

  • dotenv → For environment variables.

Step 3: Creating Proper Folder Structure :-

I created these folders:

  • models/ → For database schemas.

  • routes/ → For API routes.

  • controllers/ → For logic.

  • middleware/ → For auth & security.

  • config/ → For DB and config files.

And a main file:

  • server.js → Entry point of backend.

Step 4: Creating First Express Server :-

In server.js, I created a basic Express server with:

  • JSON middleware

  • CORS enabled

  • A test route

  • Server listening on port 5000

Step 5: Running and Testing the Server

I started the server using:

node server.js

And tested it in browser:

http://localhost:5000

When I saw the message:

Backend is running

That confirmed:

Server is working.
Express setup is correct.
Project is ready for real APIs.

Why This Setup Matters for Future?

This backend base will now be used to:

  • Build authentication system.

  • Create event APIs.

  • Create resource APIs.

  • Add role-based access.

  • Connect MongoDB.

  • Secure the application.

Why I Started This Project With Backend Instead of Frontend :-

In most student projects, people usually start by designing the UI first. But for this College Event & Resource Management System, I intentionally decided to start with the backend.The backend is the foundation of any real-world application. It is responsible for handling authentication, database operations, business logic, security, and API communication. If the backend architecture is weak, the entire project becomes unstable, no matter how good the frontend looks.

Since this project is meant to be a production-level and placement-oriented project, I wanted to first:

  • Design a scalable backend structure

  • Setup proper API architecture

  • Prepare database models and authentication flow

  • Ensure that the system can handle real data and real users

Another important reason is that the frontend depends completely on backend APIs. If APIs are not ready, frontend developers usually end up writing fake data (dummy JSON), which later causes rework.

By building the backend first:

  • My frontend will be clean and API-driven

  • There will be no rework

  • The project structure will be more professional

  • Deployment and DevOps integration will be much easier later

This is exactly how real companies build software: backend and architecture first, UI second.

Problems I Faced While Setting Up Backend (Day 2) :-

While setting up the backend, I faced multiple real-world issues which actually taught me more than a smooth setup would have.

Problem 1: Express 5 Causing 403 Forbidden Error

initially, I installed the latest version of Express (v5). Even though my server was running, when I tried to open http://localhost:5000, the browser kept showing:

  • “Access Denied – HTTP 403”

  • This was confusing because the code was correct. After debugging, I learned that:

    • Express 5 is still experimental

    • It has stricter default security rules

    • It blocks requests unless configured properly

Solution: I downgraded Express to the stable version (Express 4), which is used in production by most companies.

Problem 2: Port 5000 Already in Use Error

After fixing Express, I got another error:

  • EADDRINUSE: address already in use :::5000

This happened because my old server process was still running in the background.

Solution:

  • I learned how to find running processes using the port.

  • Killed the old process.

  • Restarted the server properly.

What I Learned From These Problems

These issues taught me:

  • How real backend debugging works.

  • How version mismatches create real production bugs.

  • How to debug ports, processes, and Node.js configuration.

  • That building backend is not just coding — it’s also system-level problem solving

SAVE DAY 2 WORK (Git) :-