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 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-objects-database

v0.0.7

Published

Simple module to work with saving/searching/deleting any objects using embed nosql file database, for small projects.

Downloads

12

Readme

node-objects-database

Simple module to work with saving/searching/deleting any objects using embed nosql file database, for small projects.

NOTE: Multiple types of objects can be stored in a single database file with different key names, if needed.

Example on RunKit: https://runkit.com/animatedcreativity/5c3f12c2f7ecd3001272016d

Usage:

var objectsDb = require("node-objects-database");
objectsDb.start("<database_file_name>"); // .nosql will be appended automatically. Use multiple instances for multiple file databases OR use different keys for different kinds of objects.
objectsDb.set("productId", {productId: "key_5678", name: "A good product", description: "This is a good product."}); // creates an object in the file database and updates it if already exists.
objectsDb.get("productId", "key_5678"); // get object by key
objectsDb.insert("productId", {productId: "key_5679", name: "Another good product", description: "This is another good product."}); // inserts new object, if the key already exists it will be ignored.
objectsDb.update("productId", {productId: "key_5679", name: "Another good product", description: "This is another good product.", weight: "1.2 kg"}); // updates an existing object, ignores if not already added.
objectsDb.find(); // gets all objects in the file database
objectsDb.find("productId", "key_5678"); // same as objectsDb.get("productId", "key_5678"); as it gets single object
objectsDb.find("productId"); // gets all objects which have the key name productId
objectsDb.find({name: "Another good product", weight: "1.2 kg"}); // searches multiple fields and gets all the related objects
objectsDb.count(); // gets count of all objects in the file database
objectsDb.count("productId") // gets count of objects with particular key only
objectsDb.remove("productId", "key_5678"); // searches by key and removes the object, ignores if not found
objectsDb.clear(); // clears all objects from the file database

IMPORTANT: All the above methods are asynchronous, so you should use .then .catch to check if actions are done, for example:

objectsDb.set("productId", {productId: "key_5678", name: "A good product", description: "This is a good product."})
  .then(function(response) {
    // object was saved.
  })
  .catch(function(error) {
    // error occured.
  });

OR

var objectsDb = require("node-objects-database");
objectsDb.start("database_file_name");

(async function() {
    await objectsDb.set("productId", {productId: "key_5678", name: "A good product", description: "This is a good product."});
    var product = await objectsDb.get("productId", "key_5678");
    console.log(product);
    await objectsDb.insert("productId", {productId: "key_5679", name: "Another good product", description: "This is another good product."});
    var products = await objectsDb.find();
    console.log(products);
})();

objectsDb.db(); // returns full nosql object to work with

Version history:

v0.0.5: Fixed .get() to return single object instead of array.

v0.0.6: Fixed .set() updating object if it exists. Issue came because of 0.0.5 update. Made .set() & .update() more flexible. Instead of overwriting full object, an object is now actually saved by checking what properties it already has and adding/updating new ones.