Socket
Socket
Sign inDemoInstall

mongo-database-handler

Package Overview
Dependencies
226
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    mongo-database-handler

Local database handler


Version published
Weekly downloads
9
Maintainers
1
Created
Weekly downloads
 

Readme

Source

mongo-database-handler

A simple MongoDB database handler for NodeJS. This package works with various uses, e.g. discord.js, express.js, etc. Assuming you may already know how to use MongoDB and Mongoose.

Usage

To initiate the database handler, put this code inside your code.

Typescript:

import { DatabaseHandler } from "mongo-database-handler";
import path from "path";

// Put your Models' directory inside the init() function.
// Remember to put this inside an async function for the await to work.
await new DatabaseHandler().init(path.join(__dirname, "models"));

Javascript/NodeJS:

const { DatabaseHandler } = require("mongo-database-handler");
const path = require("path");

// Put your Models' directory inside the init() function.
// Remember to put this inside an async function for the await to work.
await new DatabaseHandler().init(path.join(__dirname, "models"));

To create a model, simply look at this example.

Typescript:

import { Model } from "mongo-database-handler";

// Replace Model with whatever name you like for the model.
class Model extends Template {
	constructor() {
		super(
			{
				name: {
					type: String,
				},
				value: {
					type: String,
				},
			},
			"name"
		);
	}
}

FAQs

Last updated on 28 Jul 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc