mongo-database-handler
TypeScript icon, indicating that this package has built-in type declarations

0.0.14 • Public • Published

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"
		);
	}
}

Readme

Keywords

none

Package Sidebar

Install

npm i mongo-database-handler

Weekly Downloads

0

Version

0.0.14

License

ISC

Unpacked Size

6.11 kB

Total Files

6

Last publish

Collaborators

  • icytea