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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@sasm/db

v1.0.1

Published

MongoDB driver for SASM

Downloads

1

Readme

SasmDB

MongoDB driver for SASM

NPM Version Node Version MongoDB Version Sasm Version SasmDB Version

Install

SASM DB is a private extension package under the @sasm organization on NPM. You must be an authorized user of the @sasm organization to install SasmDB Version.

npm login

Once you have logged into NPM as an authorized @sasm user, you may install SasmDB Version.

npm i @sasm/db

Usage

Please see Sasm Version for information on how to use Sasm and extensions.

MongoDB Version is required in order to use SasmDB Version. Configuring and setting up a database is beyond the scope of this documentation. Please see the documentation on MongoDB Version for more information on setting up and running MongoDB.

Requiring the SasmDB Version extension will use the configuration from Sasm Version to make a database connection. By default, there is no authentication specified in the database connection configuration.

No configuration is necessary if you start you MongoDB server with this command:

mongod --dbpath data

However, it is recommended you use the --auth argument (or some other form of authentiaction) for security purposes.

Configuration

Configuring the connection string is possible through Sasm Version configuration. Recall from the Sasm System documentation that the default configuration looks like this:

{
	"connection": {
		"hostname": "localhost",
		"ip4": "127.0.0.1",
		"ip6": null,
		"port": 8080
	},
	"database": {
		"username": null,
		"password": null,
		"address": [
			{
				"host": "localhost",
				"port": 27017
			}
		],
		"name": "sasm",
		"options": {}
	}
}

If you left the default confuration as-is, which is recommended, you can make changes to this confuration before running sasm.start().

Here's an example of a working database connection to a MongoDB Version service with a database named "sasm" and a user on the sasm database named Admin with the password changeMe.

mongod command:

mongod --dbpath data --auth

server.js

const sasm = require('@sasm/system');

sasm.prep.config.database.username = "Admin";
sasm.prep.config.database.password = "changeMe";

sasm.
	start().
	registerExtension("@sasm/db").
	listen();

Before the above server will work correctly, you must set up a mongo user.

** Note: The @sasm/db driver will not try to connect until a query is attempted, so you will not see a connection or authentication error even if the confuration is wrong or if the database is not started/installed.** It is necessary to test your connection by running a query.

Setting up the Mongo User

Though beyond the scope of this documentation, we'll go over setting up a basic user using the Mongo Shell.

First, start the database by opening a terminal and executing this command:

mongod --dbpath data

In another terminal, start the mongo shell.

mongo

In the mongo shell, switch to the sasm database (MongoDB will create it automatically if it doesn't exist yet).

use sasm

You should see the message:

switched to db sasm

Now, create a user for the sasm database:

db.createUser({
  user: "Admin", 
  pwd: "changeMe", 
  roles: ["readWrite"]
})

You should see the message:

Successfully added user: { "user" : "Admin", "roles" : [ "readWrite" ] }

Testing your Connection

To test your connection, with the above authentication as an example, simply run a query. Here's an example of server.js with the @sasm/db extension, a username and password, and a query to an empty collection:

const sasm = require('@sasm/system');
sasm.prep.config.database.username = "Admin";
sasm.prep.config.database.password = "changeMe";

sasm.
	start().
	registerExtension('@sasm/db').
	listen();

// Testing the connection:
let users = sasm.db.collection("users");
users.find((err, docs) => {
	if (err) {
		console.log(err);
	}
	console.log(docs);
});

You should see output similar to this (host will vary):

Listening on: 6::::8080
DB Connected on: mongodb://Admin:changeMe@localhost:27017/sasm
[]

The last line, [] is the docs from the users collection. If we see that, we know our app is communicating with our database. The test portion of the above code can be removed now that we know it's possible to connect with our configuration.

License

LICENSE.md