Inside the Code: A Developer’s Guide to My Node.js Blog
This blog isn’t powered by WordPress, Ghost, or any third-party CMS. I built it using Node.js, Express, MongoDB, and EJS all from scratch.
Here’s a peek under the hood at how it works.
🛠️ Tech Stack Overview
- Node.js + Express for the server and routing
- MongoDB (with Mongoose) for storing blog posts
- EJS for rendering dynamic templates
- Static assets in
/publicfor CSS, JS, and images
📁 Project Structure
├── server.js
├── routes/
│ └── articles.js
├── views/
│ └── articles/
│ ├── index.ejs
│ └── show.ejs
├── models/
│ └── article.js
├── public/
│ └── scripts/
│ └── NumberFormatter.js
🔁 The Main Flow
1. Home Route (/)
In server.js:
app.get('/', async (req, res) => {
const articles = await Article.find().sort({ createdAt: 'desc' });
res.render('articles/index', {
articles,
formatWithAbbreviation
});
});
- Fetches all articles from MongoDB
- Sorts them by creation date (newest first)
- Passes them into an EJS template along with a number formatter
2. Article Routes (/articles)
In routes/articles.js, I handle:
- New post creation
- Editing
- Deletion
- Viewing individual posts
EJS templates handle the views, and Mongoose manages the database logic.
🧮 Formatting Numbers Smartly
I wrote a tiny utility: NumberFormatter.js.
// Example usage
formatWithAbbreviation(12400); // "12.4K"
This keeps the blog clean and modern, especially for stats like views or likes.
🎨 Static Assets
app.use('/public', express.static('./public'));
All my CSS, JS, and media live in /public, and Express serves them directly.
🔐 Dev-Friendly Extras
- Method Override to allow PUT/DELETE in HTML forms
- Environment variables for database config
- Middleware for parsing form data
🧠 Final Thoughts
This blog isn’t just a writing platform—it’s a playground for learning full-stack web development. I control every part of the stack, from server logic to templating and deployment.
If you’re thinking of building your own blog from scratch, I say go for it. It’s the best way to truly understand how the web works.

Leave a Reply
You must be logged in to post a comment.