API Express.js – Technigo Bootcamp Project 2026#44
API Express.js – Technigo Bootcamp Project 2026#44KausarShangareeva wants to merge 4 commits intoTechnigo:masterfrom
Conversation
There was a problem hiding this comment.
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"], | ||
| }, |
There was a problem hiding this comment.
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" }); | ||
| } |
There was a problem hiding this comment.
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" }); | ||
| } |
There was a problem hiding this comment.
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) => { |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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"], | ||
| }, |
| { method: "POST", path: "/thoughts/:id/like", description: "Like a thought" }, | ||
| ], | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Nice idea documenting the API routes here. Makes it easy to see what endpoints exist.
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:
Backend:
Key Features
Tech Stack
API Endpoints
//thoughts/thoughts/:id/thoughts/thoughts/:id/thoughts/:id/thoughts/:id/likeGetting Started
npm install.envfile with your MongoDB connection string:npm run devRESET_DB=falsein.env