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 🙏

© 2025 – Pkg Stats / Ryan Hefner

localjsondb

v0.1.3

Published

A very simple local json file database for Node.js that can be used for prototyping and small projects.

Downloads

22

Readme

LocalJsonDB Build Status

A very simple local json file database for Node.js that can be used for prototyping and small projects.


The API includes only 3 operations (.get(), .set(), .del()), designed for basic addition, removal, retrieval and filtering with pagination. All operations work synchronously on the database in memory, and asynchonously save changes to a json file. The current implementation does not support concurrent access.

Tables are essentially just lists of JSON objects where rows are schemaless and require only a single field (a unique key).

A helper method is also provided (.expressRouting()) that can be used as express middleware, this enables a simple rest api service with get, post, put and delete operations corresponding to the methods previously mentioned. Items are accessed at a configured endpoint eg 'api/[tableName]/' or 'api/[tableName]/[uniqueId]/'. Items in the db can be accessed in batch by using the body of a post or put.

Installation

npm package: https://www.npmjs.com/package/localjsondb

npm install localjsondb
npm install express body-parser // (optional - to use express with rest api)

API

db = new LocalJsonDB({ "fileName": <fileName>, "prettyJSON": <bool(false)>, "tables": { <setName>: <setUniqueFieldKey>, ... } });

[itemsAffected] = db.set(<tableName>, <itemOrArray>, { "throwOnDuplicate" : <bool(false)> });
[itemsAffected] = db.del(<tableName>, <uniqueIdOrArray>);
[itemMatches] = db.get(<tableName>, <matchObjOrArray>, { "exactMatch": <bool(false)>, "ignoreCase": <bool(false)>, "orderBy": <fieldName(null)>, "orderAscending": <bool(false)>, "offset": <number(0)>, "limit": <number(-1)> });
[expressAllHandler] = db.expressRouting();

where <matchObjOrArray> is one of:
* Single or array of unique keys in the target table.
* Single or array of objects to match against, eg: { <fieldName>:<matchValue>, <fieldName2>:<matchValue2>} means retrieve all values where rows (fieldName contains matchValue or fieldName2 contains matchValue2)

Examples

tests/test.js - advanced usage examples.
examples/example-basic.js - basic usage examples.
examples/example-express.js - real use case example hosting the rest api with express, and an html client to talk to it with.

Run the express example:

npm install express body-parser localjsondb
node node_modules/localjsondb/examples/example-express.js

Then browse to localhost:8080:
LocalJsonDB example with express example

Improvements

  • Write as a C++ plugin to improve performance beyond what Node.js can offer.
  • Investigate ways to allow concurrent access.
  • Improve search when sorting to sort by relevance.
  • Recover from process end (maybe save synchronously when process is going to end)

Releases

0.0.1 - Basic working package.
0.0.2 - Adding test cases.
0.0.3 - Added many more test cases, updated API and optional search params.
0.0.4 - Updated to include a basic Express routing method.
0.1.0 - Minor changes, ready for npm publish.
0.1.1 - Minor changes, fixed issue with auto-increment of index when it is not provided.
0.1.2 - Minor changes, fixed issue when using integers vs strings as table indices.
0.1.3 - Minor changes, Added ability to specify multiple orderBy and orderByAsc values in an array[string] and array[boolean] format.