External Publication
Visit Post

Day 48 of Leaning MERN Stack

DEV Community [Unofficial] June 20, 2026
Source

Hello Dev Community! 👋

It is officially Day 48 of my unbroken full-stack engineering journey! Yesterday, I refactored my modular core patterns into MVC architecture. Today, I linked up a major functional extension inside the /model layer by introducing JavaScript Classes (OOP) to coordinate my local file operations and storage data patterns!

Instead of writing loose object definitions, I stepped up my enterprise game by structuring a reusable class footprint that encapsulates data parameters and handles non-blocking file-system persistence asynchronously.

🧠 Key Learnings From Day 48 (OOP Modeling & File Systems)

As clearly shown in my development workspace layout within "Screenshot (116).png" , modeling data with dedicated classes shifts your core structural logic from simple scripts into highly scalable engines:

1. The Model Data Blueprinter (constructor)

I used the standard ES6 class framework inside home.js to structure an explicit data mold (houseList) with attributes tracking: houseName, price, location, rating, and photoUrl. This ensures every entry traveling through our server follows an identical structure.

2. Streamlining Async Persistence (save())

Rather than relying on globally declared floating arrays, my .save() blueprint method triggers an internal lookup to read existing data stacks asynchronously before safely using fs.writeFile() to serialize and flash mutated JSON rows into a local data asset (homesdata.json).

3. Static Decoupled Fetchers (static fetchAll())

I mastered using static methods. Since reading a data grid requires pulling records without creating an instance of a single house first, making fetchAll(callback) static allows our controllers to tap the hard disk records straight from the class reference layout:

javascript
// A conceptual look at my file-reading design today
static fetchAll(callback) {
    const filePath = path.join(rootDir, 'data', 'homesdata.json');
    fs.readFile(filePath, (err, data) => {
        if (err) {
            callback(JSON.parse(data));
        } else {
            console.log(err);
        }
    });
}

Discussion in the ATmosphere

Loading comments...