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

am_ecomhelper

v1.1.0

Published

This is ecom helper

Downloads

9

Readme

am-ecomhelper

1. MongoDB Connection Utility

A robust utility designed to streamline MongoDB connections using Mongoose within your Node.js applications. This versatile tool simplifies the process of establishing secure and efficient connections to MongoDB databases, enhancing the development experience for seamless integration with your Node.js projects.

Installation

To use this utility, make sure you have Node.js installed. Then, install the required dependencies:

npm install mongoose

About Function

This is how the function is working internally.

  • Prototype

Connect_MongoDB(Mongo_URI, family);
  • Details

Default -
    Mongo_URI: "mongodb://localhost:27017"
    family: 4, 6
Details -
    Mongo_URI = MongoDB connection string.
    family: IP version (4 for IPv4, 6 for IPv6).
    return  Promise<boolean>;

Error Handling

The utility throws an error if the MongoDB connection fails. Ensure to handle errors appropriately in your application.

Documentation

To learn how to use this package properly Read the offical documentation (Link provided below). Just need to copy and paste the code provided in this documentation.

Documentation

2. Model Creation

  • Mongoose simplifies MongoDB data modeling in Node.js, providing an elegant schema-based solution. It enhances data validation, facilitates schema creation, and streamlines interactions with MongoDB, enabling efficient and structured data management in applications.

    • But, my package revolutionizes Mongoose and MongoDB integration, providing unparalleled ease in schema creation, validation, and data modeling for Node.js applications, ensuring seamless development and enhanced productivity
  • Schema Object Creation

    Here the packages Provides 5 functions to create schema object

    function(...)             => return type
    
    generateStringField(...)  => object
    generateDateField(...)    => object
    generateBooleanField(...) => object
    generateNumberField(...)  => object
    generateRefIdField(...)   => object
  • Prototype

    • All the parameters are optional and depends on your application configuration if you don't want to use a single one then also it'll work accordingly
    • Suppose If you wnat to use the _default but you don't want to use required in that case you've to provide a undefined for those parameters

    |sno| generateStringField(...)|generateNumberField(...)|generateDateField(...)|generateBooleanField(...)|generateRefIdField(...)| |---|-----------------------------|----------------------------|--------------------------|-----------------------------|---------------------------| | 1 | required (Boolean) | required (Boolean) | required (Boolean) | required (Boolean) | required (Boolean) | | 2 | _default (Str/Num/Bool) | _default (Num/Bool) | _default (Date/Bool) | _default (Boolean) | ref (String) | | 3 | unique (Boolean) | unique (Boolean) | unique (Boolean) | - | - | | 4 | lowerCase (Boolean) | min (Number) | min (Number) | - | - | | 5 | upperCase (Boolean) | max (Number) | max (Number) | - | - | | 6 | minLength (Number) | - | expires (Num/Str) | - | - | | 7 | maxLength (Number) | - | - | - | - |

  • Details

    const testSchema = {
      name: generateStringField(
        true,
        "ANIRBAN MISHRA",
        false,
        false,
        true,
        7,
        20
      ),
      Date: generateDateField(
        true,
        new Date(),
        false,
        new Date(),
        new Date("2023-12-31"),
        60 * 60 * 24 //24 Hours In Seconds,
      ),
      isAdmin: generateBooleanField(true, false),
      age: generateNumberField(true, 20, false, 18, 100),
      ref_model: generateRefIdField(true, "User"),
    };
    • Parameter Skipping

      • If you don't need a parameter you can a skip it
      const testSchema = {
        name: generateStringField(
          undefined,
          "ANIRBAN MISHRA",
          false,
          undefined,
          true,
          7,
          20
        ),
        ...
      };
  • Advantage
    1. This is how easier to use this function to create the schema object.
    2. Each and every parameters are given in the prototype table.
    3. It makes the code shorter and more easy to understand for freshers.
    4. This Will generate the schema object not the schema, now the next thing is to create the model using this schema object
  • Model Creation

    Previously the discussion was regarding schema object creation, now after the schema is created we need to create a mongoose model

    Here am-ecomhelper provides a function to create a model

    createMongooseModel("test", schema, true);
    • Parameters

      createMongooseModel("database_model_name", schema, timestamps);
      
      Default -
          database_model_name: string
          schema: object
          timestamps: false
  • Details

    const testModel = createMongooseModel("test", schema, true);
    model1.create({
      name: "ANIRBAN Mishra",
      Date: Date.now(),
      isAdmin: false,
      age: 145,
      ref_model: "65530ce5e081d5e1a255025b",
    });
    • This will give me a mongoose model where I can perform all other actions like
    .create()
    .deleteOne()
    .findById()
    .findOne()
    .find()
    .deleteOne()
    ...

Feedback

If you have any feedback, please reach out at my

email

Issues

If you are facing issuses while using this package, you can raise issue in the official github repository's Isuuse Section. Clice here to raise an issue

License

MIT License

Copyright (c) 2023 ANIRBAN MISHRA

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Author

@anirban-629

🔗 Links

portfolio linkedin instagram