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

connrun

v1.0.1

Published

Easily connect to mongodb, and run what you want to run!

Downloads

8

Readme

ConnRun

What doe's this library? Honestly nothing special. It's just connecting to "mongodb" database for you, and additionally gives you some pattern, that you can deside to use or not. That's it. It's just connect to db, and give you a client instance on which you can perform same stuff as you was before. And in turn, It's still your responsability to configure this connection. And now you think, why i need this package, if I still responsible for all this routine stuff, and this how I answere to this question -

IF (

  1. You dont want to run again and again through same steps of diving in to the mongod nodejs driver documentation to see the examples of how they do that stuff, and implement same thing one to one, maybe with some variable name changes in your project.
  2. Or you simply want to start learn mongodb with native driver, immediately starting from CRUD Opperations for example.
  3. You want to fetch some data from somewhere as soon as posible, and store it somewhere, and you allready now how to use mongodb nodejs driver, then just install this package in your project, give it a url, and immediately get client instance to perform opperartions...
  4. You can not make a choice on how it is more convenient to pass your client instance to your functions, maybe alongside to your regular arguments, or maybe differently, well, I'll give you a pattern, I think is not bad, at least its good for fast projects, for which I designed this package originally.

) Then this library may be usefull for you.

Installation

  1. Navigate to your project folder. cmd: cd myprojectDir
  2. If your project still not initialized by npm, i.e. theres no package.json file, initialize It, for simplicity you can just type cmd: npm init -y
  3. Install the package locally. cmd: npm i -S connrun ( Same as cmd: npm install --save connrun )

Usage

Let me descibe It's simplest usage. Just look at the code below:

const { connRun } = require('connrun') 

const MONGODBURI = 'mongodb://localhost:8000'

const connRunCallback = ({ client }) => () => client

const yourApp = async () => {
        const client = await ConnRun({ url: MONGODBURI }, connRunCallback)
        // // Do Some stuff...

        // // 1. For example:
        // const db = client.db('mydb')
        // const collection = db.collection('mycollection')
        // // and soo on...

        // // 2. Or call your own functions
        // await myfunction(client, ...args)

        await client.close()
}

Here we simply pass to ConnRun function "options" object with url property which contains url of database - as first parameter, and a function which returns another function, which are will be executed by connRun automaticaly - as second parameter, and we get MongoClient instance after promise returned by connRun function resolves, and thereafter we do anything what wee need.

But now lets consider the case when we have to write some functions which are rely on client instance, then we might deside how to pass that client instance to that functions to get most convenient and most consistant way to stick with afterwardes in our project when writing such a functions... For that reasone I introduce a pattern, which can help you on that way, Lets write all our functions which expect client instance, following this pattern: ({ client }) => () => //mystuff Benefits of this pattern are following:

  1. In this case arguments of your base function will not interfere with arguments, that ConnRun will pass to you. and in case when you deside to change signiture of your base function, It will be truly simple.
  2. You can reuse this functions without ConnRun, as any function you write with this pattern In the end has all nessesery arguments to internally call another functions with the same pattern.
  3. And of course afterwards you can follow this pattern to very end of your project. See The Examples

That's It, hop this will be useful for you

TypeDefinitions

See typedefs

You Can Get ConnRun either as default export or named export... And if writing with vanila javascript, using const ConnRun = require('connrun') you not getting features like intelliSence, try to use named exports: const { ConnRun } = require('connrun')