Build a JSON Database in Node.js

6 min read·Dec 5, 2025

Article banner

Welcome to Code in Action, the series where we build practical backend projects, step by step.

In this series, we're going to build RowStackDB — a lightweight, file-based relational database written in Node.js that stores data as structured JSON.

Unlike in most tutorials out there, you won't just learn how to serialize and parse JSON, or read and write from and to file.

You'll learn how to implement an actual Node.js database engine with a clean ORM-like API to:

  • Define tables and their data structures:

    import { RowStackDB, DataTypes } from '@learnbackend/rowstackdb';
    
    const db = new RowStackDB('learn_backend');
    
    const Users = db.define('users', {
      id: {
        type: DataTypes.INTEGER()
      },
      email_address: {
        type: DataTypes.VARCHAR()
      },
      account_type: {
        type: DataTypes.ENUM(),
        values: ['freemium', 'premium'],
        defaultValue: 'freemium'
      },
      status: {
        type: DataTypes.ENUM(),
        values: ['active', 'inactive', 'pending'],
        defaultValue: 'pending'
      },
      city: {
        type: DataTypes.VARCHAR(50)
      }
    });
    
  • Perform CRUD operations on these tables:

    const results = Users.find({
      where: {
        $and: [
          { account_type: { $eq: 'premium' }},
          { $or: [
            { city:  { $eq: 'Montreal' } },
            { city:  { $eq: 'Quebec' } }
          ] }
        ]
      },
      order: ['id', 'desc'],
      attributes: ['id', 'email_address', 'status'],
      limit: 5
    });
    

As well as built-in mechanisms to:

  • Load and persist data from and to the disk.
  • Validate and sanitize data before it is committed to the database.

Its architecture will be class-based, allowing us to cleanly separate concerns between the database engine, table handlers, and data types — making it easy to extend, reuse, or even publish as an npm package later on.

This project is perfect for prototypes, CLIs, or just learning how relational databases and ORMs work under the hood.

Here are the links to the tutorials:

Unlock the program 🚀

Pay once, own it forever.

€79

30-day money-back guarantee

  • 13 modules
  • 113 lessons with full-code examples
  • 29 projects with commented solutions
  • All future lesson and project updates
  • Lifetime access

By submitting this form, you agree to the Terms & Conditions and Privacy Policy.