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

@fohletex/forerunnerdb-debugger

v0.1.0

Published

A tiny library to quickly fetch and debug the database contents of ForerunnerDB

Downloads

3

Readme

@fohletex/forerunnerdb-debugger

This is a tiny debugger that allows you to quickly check the contents stored in a ForerunnerDB.

How to setup

yarn add @fohletex/forerunnerdb-debugger

or resp.

yarn add --save-dev @fohletex/forerunnerdb-debugger

if you just want to use it for internal dev purposes (e.g. doing some data checks during a unit test).

How to use it

:warning: WARNING For the next steps I assume you've already setup a valid forerunner db instance and are familiar with the common handling of the ForerunnerDb library. If not, I advise you to go through their documentation carefully. It is worth to read. If you want to skip that for now I advise you to just have setup the forerunner instance itself and initialized an appropriate database.

First of all you need to establish the debugger and connect it with your ForerunnerDB instance, that you've already setup (see yellow box above for more information on how to setup the forerunner instance).

const fdbgr = new ForerunnerDbDebugger(db); /* db: you're forerunner db object */

At current the debugger contains three functionalities that were very helpful for me to get a quick overview during runtime or checking my production systems in the frontend when I doubt that not all data was given to my backend. This

  1. list collection names
  2. quickly listing the data
  3. print all data

List Collection Names

The collection names are accessible via a general object property collectionNames.

const { collectionNames } = fdbgr;

Will return a list of strings representing the collection names.

List all data

const allData = fdbgr.toJSON();

Will return an object which contains as keys the names of all collections currently known to the database and as appropriate values a list of all data entries in the appropriate collections. The indexes of the data entries are the same as stored in the database!

Example Output:

const coll = db.collection('test');
coll.insert([{ fruit: 'apple' }, { fruit: 'banana' }]);

console.log(fdbgr.toJSON());

/**
 * Will output somthing like:
 * 
 * { test: [ { _id: 'e89jiljjf', fruit: 'apple' }, { _id: 'b8sfj9u8', fruit: 'banana' } ] }
 */

Print data in readable format

Especially when the database contains more data than usual, it might be good to watch the data in a more human-readable format to quicker detect content issues, therefore you may want to use this method:

fdbgr.prettyPrint();

/**
 * Will output something like:
 * 
 * =====================================================
 * = test
 * =====================================================
 * 0 | { _id: 'e89jiljjf', fruit: 'apple' }
 * 1 | { _id: 'b8sfj9u8', fruit: 'banana' } 
 */

But, what if I have a very large database?

If you have a lot of data stored in your forerunner database you probably may not want to print the whole contents. Therefore you may set a filter limit, as in the following example. Note, this output will limit all collections connected to the database, no matter how many entries they have.

fdbgr.prettyPrint(1);

/**
 * Will output something like:
 * 
 * =====================================================
 * = test
 * =====================================================
 * 0 | { _id: 'e89jiljjf', fruit: 'apple' } 
 */

And yes! Of course this filter option is also available for the toJSON-method:

const jsonWithLimit = fdbgr.toJSON(1);
console.log(jsonWithLimit);

/**
 * Will output somthing like:
 * 
 * { test: [ { _id: 'e89jiljjf', fruit: 'apple' } ] }
 */

Happy debugging!