npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

dbnext

v1.2.0

Published

File-based JSON DB with model + file upload support

Downloads

3

Readme

dbnext

A lightweight JSON-based file database with optional file uploads — perfect for CMS-like systems and editable sites using Next.js.


🚀 Features

  • ✅ Simple JSON file-based storage (no DB required)
  • 📂 File upload support using formidable
  • 🧩 Optional schema modeling via JS model files
  • 🔍 Nested path access like db.get("hero.title")
  • 📝 Easy integration with Next.js API routes
  • 🕒 Snapshot history & revert functionality

📦 Installation

npm install dbnext

📁 Project Structure

your-app/
├── api/
│   └── content.js       # Next.js API using dbnext + upload
├── models/
│   └── headerModel.js   # Optional default model structure
├── public/
│   └── uploads/         # File uploads go here
├── data/
│   └── content.json     # Stored JSON data
└── node_modules/

🧠 How It Works

  • Uses fs to persist data into a .json file
  • Allows nested updates via paths like hero.title
  • Supports file uploads (e.g., images) and stores path
  • Automatically creates file if not found
  • Tracks snapshots for undo support

📘 Basic Usage

1. Initialize with model

const dbnext = require('dbnext');
const headerModel = require('./models/headerModel');

const db = new dbnext('data/content.json', headerModel);

2. Update data

db.set('hero.title', 'Welcome to my portfolio');

3. Access data

console.log(db.get('hero.title')); // → "Welcome to my portfolio"

4. Push to array

db.push('projects', { name: 'Portfolio', link: 'https://...' });

📤 File Upload Integration (API)

Use this in pages/api/content.js in a Next.js project:

import { IncomingForm } from 'formidable';
import fs from 'fs-extra';
import path from 'path';
import dbnext from 'dbnext';
import headerModel from '@/models/headerModel';

export const config = {
  api: { bodyParser: false },
};

const uploadDir = path.join(process.cwd(), 'public/uploads');
fs.ensureDirSync(uploadDir);

const db = new dbnext('data/content.json', headerModel);

export default async function handler(req, res) {
  if (req.method === 'GET') {
    return res.status(200).json(db.get());
  }

  if (req.method === 'POST') {
    const form = new IncomingForm({ uploadDir, keepExtensions: true });

    form.parse(req, (err, fields, files) => {
      if (err) return res.status(500).json({ error: 'Upload failed' });

      const updated = {
        ...fields,
        ...(files?.image?.[0] && {
          image: `/uploads/${path.basename(files.image[0].filepath)}`
        }),
      };

      Object.entries(updated).forEach(([key, value]) => {
        db.set(key, Array.isArray(value) ? value[0] : value);
      });

      res.status(200).json({ success: true, data: db.get() });
    });
  } else {
    res.status(405).json({ error: 'Method not allowed' });
  }
}

📂 Example Model (headerModel.js)

module.exports = {
  hero: {
    title: '',
    subtitle: '',
    image: ''
  },
  about: {
    bio: '',
    image: ''
  },
  projects: [],
  contact: {
    email: '',
    phone: ''
  }
};

🔁 Revert Support

db.set('hero.title', 'New Title', { track: true });
db.revert(); // undo last change

🧪 Sample API Test

curl http://localhost:3000/api/content
curl -X POST http://localhost:3000/api/content \
  -F "hero.title=Updated" \
  -F "image=@/path/to/image.png"

🛡 License

MIT © Saurabh Singh