Skip to content

Comments

API Express.js – Technigo Bootcamp Project 2026#44

Open
KausarShangareeva wants to merge 4 commits intoTechnigo:masterfrom
KausarShangareeva:master
Open

API Express.js – Technigo Bootcamp Project 2026#44
KausarShangareeva wants to merge 4 commits intoTechnigo:masterfrom
KausarShangareeva:master

Conversation

@KausarShangareeva
Copy link

Please include your Render link here.

Happy Thoughts API

Hi there! I built this Happy Thoughts API as part of my Technigo JavaScript Bootcamp 2025 journey. This is a RESTful API built with Express.js and MongoDB that lets users create, read, update, and delete happy thoughts, as well as like them.

View it live

Frontend:

You can check out the live website here: Happy Thoughts Explorer

Backend:

You can check out the api server in Render: API Explorer

Key Features

  • Full CRUD operations: Create, Read, Update, and Delete thoughts
  • Like (heart) a thought
  • Data stored in MongoDB with Mongoose models
  • Input validation (message must be 5-140 characters)
  • Error handling with proper HTTP status codes
  • Database seeding with sample data

Tech Stack

  • Node.js
  • Express.js
  • MongoDB + Mongoose
  • dotenv

API Endpoints

Method Path Description
GET / API documentation
GET /thoughts Get all thoughts (newest first, limit 20)
GET /thoughts/:id Get a single thought by ID
POST /thoughts Create a new thought
PATCH /thoughts/:id Update a thought
DELETE /thoughts/:id Delete a thought
POST /thoughts/:id/like Like a thought (+1 heart)

Getting Started

  1. Install dependencies: npm install
  2. Create a .env file with your MongoDB connection string:
    MONGO_URL=mongodb+srv://your-connection-string
    RESET_DB=true
    
  3. Start the server: npm run dev
  4. After seeding, set RESET_DB=false in .env

Copy link

@irisdgz irisdgz Feb 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super solid Happy Thoughts API — clean structure, good validation, authentication works well, and the routes are easy to follow. No major issues. Nice job!

required: [true, "Email is required"],
unique: true,
match: [/.+@.+\..+/, "Please enter a valid email"],
},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good validation setup here , nice requirements and helpful error messages. makes the API safer and easier to debug.

const token = req.header("Authorization");
if (!token) {
return res.status(401).json({ error: "Not logged in" });
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice reusable auth middleware. Easy to follow and attaching the user to req.user makes the protected routes very readable.

}
if (String(thought.user) !== String(req.user._id)) {
return res.status(403).json({ error: "You can only edit your own thoughts" });
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works fine. One alternative could be using thought.user.equals(req.user._id), which is a bit more Mongoose-style for comparing ObjectIds.

});

// GET /thoughts/:id - get one thought
app.get("/thoughts/:id", async (req, res) => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice clear route logic here. Easy for me to follow the flow from request to database query and toresponse.


const app = express();
app.use(cors());
app.use(express.json());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good middleware setup. Makes sure the API can properly read JSON from the frontend.

required: [true, "Message is required"],
minlength: [5, "Message must be at least 5 characters"],
maxlength: [140, "Message must be at most 140 characters"],
},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice message validation rules..

{ method: "POST", path: "/thoughts/:id/like", description: "Like a thought" },
],
});
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice idea documenting the API routes here. Makes it easy to see what endpoints exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants