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

insta-mongo

v0.0.8

Published

Instantly start a MongoDB dev server and load database fixtures

Downloads

273

Readme

insta-mongo

Instantly start a MongoDB dev server and load database fixtures.

You need Node.js installed to use insta-mongo.

Support the developer

Click here to support the developer.

An example

See here for an example of insta-mongo in a simple Node.js/Express app.

Install it

Install globally:

npm install -g insta-mongo

Install locally to use as a development database for your Node.js project:

npm install --save-dev insta-mongo

Run it

In your terminal, run it globally:

insta-mongo

Or run it locally:

npx insta-mongo

You now have a MongoDB database server with a REST API to load database fixtures*.

* A database fixture is a particular named set of test data for your application.

Integrate it in your Node.js project

To create a dev database that runs while your Node.js application is running use concurrently.

Your start and start:dev script in your package.json will look something like this:

{
    "scripts": {
        "start": "node index.js",
        "start-db": "insta-mongo",
        "start:dev": "concurrently \"npm run start-db\" \"npm start\" --kill-others"
    }
}

Using the flag --kill-others will stop the database server when your Node.js application terminates.

Usage

[npx] insta-mongo [options]
Options:

 --db-port=<port-no>            Sets the port for the database server.
                                Defaults to 5001.
 --rest-port=<port-no>          Sets the port for the REST API      
                                Defaults to 5000.
 --db=<database-name>           Sets the database into which to load 
                                the initial fixture.
 --load=<fixture-name>          Loads an initial named database fixture.
 --fixtures=<path-to-fixtures>  Sets the path that contains database fixtures.
                                Defaults to ./fixtures.

Database fixtures:

Place your database fixtures under ./fixtures like this:

./fixtures/
    fixture-1/
        collection1.json
        collection2.json
    fixture-2/
        another-collection.js

Each JavaScript or JSON file is loaded into it's own collection that is the same as the name of the file.

See example JavaScript collection here.

See example JSON collection here.

REST API end points

Hit the following endpoints to load and unload your database fixtures.

Loads a fixture:

HTTP GET http://localhost:5000/load-fixture?db=<db-name>&fix=<your-fixture-name>

Unloads a fixture:

HTTP GET http://localhost:5000/unload-fixture?db=<db-name>&fix=<your-fixture-name>

Drops a named database collection:

HTTP GET http://localhost:5000/drop-collection?db=<db-name>&col=<collection-name>

Gets the contents of a collection.

HTTP GET http://localhost:5000/get-collection?db=<db-name>&col=<collection-name>

See a VS Code REST Client script that exercises these REST APIs.

Acknowledgements

Thanks so much to the developers of mongodb-memory-server, without this it wouldn't be possible.

https://github.com/nodkz/mongodb-memory-server

Thanks also to my earlier project that has provided the REST API for insta-mongo and has now been superseded by insta-mongo:

https://github.com/ashleydavis/db-fixture-rest-api

db-fixture-rest-api you served me well, now you can rest ;)