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

muss-rumble

v4.0.3

Published

some not common utils

Downloads

112

Readme

Muss-Rumble

This library includes a miscellanea of utilities:

  • MongoUtil to manage mongo app connections and more
  • An utility to encrypt/decrypt data easily
  • A function to transform a number from decimal to binary
  • A function to update the data of a json file with more json data
  • Provides some useful node standalone scripts that you can use directly with npm

To install it simply type

npm install --save muss-rumble

MongoUtil

This utility provides some helpers to manage mongo db based apps like connect/disconnect from a db, get the db item, etc.

How to use it

Import the module:

const { mongoUtil } = require('muss-rumble');

Helpers

updateLocalDb()

Method to populate local db with prod db data. It will connect to prod db, dump all the data on your local machine and then update local db with this data. Note that this is a destructive operation and can not be undone. All the data in your local machine will be overriden by the data on prod db. Below there is an usage example:

const localDbName = 'localDbName';
const prodDbName = 'prodDbName';
const prodDbHost = 'prodHost.mlab.com:27444';
const prodDbUser = 'eduromogo';
const prodDbPass = '12345678';
const prodDbUri = `mongodb://${prodDbUser}:${prodDbPass}@${prodDbHost}/${prodDbName}`;
const dumpLocation = 'path/to/your/backups';

mongoUtil.updateLocalDb({prodDbName, prodDbUri, prodDbHost, prodDbUser, prodDbPass, dumpLocation, localDbName})

Here you pass an object with all the info needed to connect to your prod and local dbs. The method receives an object and returns a promise that will resolve successfully if the update took place or will be rejected if it failed.

getDb(options)

Receives an options object and return the database connection object or logs an error if no db object is present.

Options object props

silent (Boolean): wether or not in should log error when failing

dropDb(db)

Receives the db connection object and returns a promise. The promise will resolve when all the collections of the db has been dropped. Pending to implement a rejection on failure.

findLastElementAdded(db, collection)

Receives a db and a collection of this db and returns the last element added to this collection.

changeGeneratedIdsToSequentialIds(db, collection)

Receives a db and a collection and return a promise. The promise will resolve after it replaces all the generated ids by sequential ids or is rejected if something went wrong.

Scripts

You can find all available scripts navigating to node_modules/muss-rumble/mongo/scripts/

To use an script simply add your own script to your package.json referencing the muss-rumble script you want to use like this:

  "scripts": {
    "yourScriptName": "node ./node_modules/muss-rumble/mongo/scripts/someScriptName.js",
  },

This comes in handy to perform some operations on db through npm so there is no need to open your GUI or mongo console.

Scripts for robomongo (or any other gui)

// This ones shows size stats for each document in a collection
db.cards.find().forEach(function(obj)
{
  const size = Object.bsonsize(obj);

  const stats = {
    '_id': obj._id, 
    'bytes': size, 
    'KB': Math.round(size/(1024)), 
    'MB': Math.round(size/(1024*1024))
  };

  print(stats);
});
// This one finds the largest document in a collection and prints its id and size
let max = {
    id: 0,
    size: 0,
};
db.cards.find().forEach(function(obj) {
    const curr = Object.bsonsize(obj); 
    if(max.size < curr) {
        max.size = curr;
        max.id = obj._id;
    } 
})
print(max);