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 🙏

© 2026 – Pkg Stats / Ryan Hefner

database-connector

v2.5.19

Published

MongoDB models package with Mongoose schemas for e-commerce applications. Includes User, Product, Store, Order and more with built-in validation and virtual properties.

Readme

Database Connector Package

MongoDB models package with Mongoose schemas for e-commerce application.

Installation

npm install database-connector

Usage

Basic Setup

const { connectToDatabase, configure, User, Product, Store } = require('database-connector');

// Configure the package (IMPORTANT: Do this before using models)
configure({
  baseURL: process.env.APP_URL || 'http://localhost:3000',
  defaultImagePath: '/images/default.png',
  defaultStoreImagePath: '/images/stores/default.jpg'
});

// Connect to database
await connectToDatabase(process.env.MONGODB_URI);

// Use models
const user = await User.findById(userId);
const products = await Product.find({ storeId });

Configuration

Important: You must configure the package before using any models that have virtual properties for image URLs (Product and Store models).

const { configure } = require('database-connector');

configure({
  baseURL: 'https://api.yourdomain.com',  // Your API base URL
  defaultImagePath: '/images/default.png', // Default product image
  defaultStoreImagePath: '/images/stores/default.jpg' // Default store image
});

Configuration Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | baseURL | string | process.env.APP_URL or 'http://localhost:3000' | Base URL for constructing image URLs | | defaultImagePath | string | '/images/default.png' | Default image path for products without images | | defaultStoreImagePath | string | '/images/stores/default.jpg' | Default image path for stores without images |

Environment Variables

The package will use process.env.APP_URL as the default baseURL if not configured explicitly. You can set this in your .env file:

APP_URL=https://api.yourdomain.com
MONGODB_URI=mongodb://localhost:27017/your-database

Available Models

  • User - User accounts and profiles
  • Store - Store/shop information
  • Product - Product catalog
  • Order - Customer orders
  • Cart - Shopping cart
  • Bill - Billing information
  • Payment - Payment transactions
  • Category - Product categories
  • StoreCategory - Store categories
  • Offer - Special offers and promotions
  • FlashDeal - Flash sale deals
  • Subscription - Store subscriptions
  • Plan - Subscription plans
  • SubscriptionOffer - Subscription offer details
  • ReductionOffer - Reduction/discount offers
  • Notification - User notifications
  • View - Product/store view tracking
  • Sale - Sales records
  • StoreRate - Store ratings
  • ResetPassword - Password reset tokens
  • PaymentType - Payment method types
  • UserAction - User activity tracking
  • Policy - Store/product policies

Virtual Properties

Some models include virtual properties that generate full URLs for images:

Product Model

  • imagesss - Returns array of product images with full URLs
  • variantImages - Returns array of variant images with full URLs
  • discounted - Returns discounted price if offer exists
const product = await Product.findById(productId).populate('offer');
console.log(product.imagesss); 
// ['https://api.yourdomain.com/uploads/product1.jpg', ...]

Store Model

  • imageUrl - Returns store image with full URL
  • rating - Calculates average rating from ratingSum/ratingCount
const store = await Store.findById(storeId);
console.log(store.imageUrl); 
// 'https://api.yourdomain.com/uploads/store-logo.jpg'

Example: Complete Setup

const express = require('express');
const { 
  connectToDatabase, 
  configure, 
  User, 
  Product, 
  Store, 
  Order 
} = require('database-connector');

const app = express();

// Configure the package FIRST
configure({
  baseURL: process.env.APP_URL || 'http://localhost:3000'
});

// Connect to database
connectToDatabase(process.env.MONGODB_URI)
  .then(() => console.log('Database connected'))
  .catch(err => console.error('Database connection failed:', err));

// Use models in your routes
app.get('/products/:id', async (req, res) => {
  try {
    const product = await Product.findById(req.params.id);
    res.json({
      ...product.toJSON(),
      // Virtual properties are automatically included with toJSON
      images: product.imagesss
    });
  } catch (error) {
    res.status(500).json({ error: error.message });
  }
});

app.listen(3000);

Swagger Documentation

All models include comprehensive Swagger/OpenAPI documentation. You can use these to generate API documentation.

Policy Schema

The Policy model can be used both as a standalone model and as an embedded schema:

const { Policy, policySchema } = require('database-connector');

// As standalone model
const policy = new Policy({ /* ... */ });
await policy.save();

// As embedded schema (already used in Product, Store, User models)
const product = new Product({
  name: 'Product Name',
  policy: {
    workingTime: { openTime: '09:00', closeTime: '18:00' },
    // ... other policy fields
  }
});

TypeScript Support

Type definitions are not included in this package yet. They may be added in future versions.

License

ISC

Changelog

See CHANGELOG.md for version history and changes.