Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@dekproject/mongoose

Package Overview
Dependencies
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dekproject/mongoose

Mongoose interface plugin for DEK

  • 1.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
2
Weekly downloads
 
Created
Source

@dekproject/mongoose

Mongoose interface plugin for DEK

What does this plugin do?

  • Control configuration for connection to Mongoose in production development mode in a simplified way with dotenv
  • Performs connection implementation along the lines ES6 being pre requirement to start the project

Instalation

To install the bootstrap we recommend using the CLI

$ yarn add @dekproject/cli --save

In the .env file add the following settings

MONGO_USER=
MONGO_PASSWORD=
MONGO_HOST=localhost
MONGO_PORT=27017
MONGO_DB=dek

For applications with cluster usage in MongoDB

MONGO_USER=
MONGO_PASSWORD=
MONGO_PATH=mongodb://mongo-01:27017,mongo-02:27017/dek?replicaSet=dek&readPreference=secondaryPreferred
MONGO_DB=dek

Usage

Using direct

$ npm i @dekproject/scope @dekproject/routes

Using in the standard DEK skeleton

import { $, app } from "@dekproject/scope";
import routes from "@dekproject/routes";

$.wait("mongoose").then(() => {
    $.app.use(await routes(process.env.ROUTES_PATH || "src/routes"));

    $.app.listen(PORT, () => {
        console.log(`App listening on port ${PORT}!`);
    });
});

Model

import { mongoose } from "@dekproject/scope";

const Schema = mongoose.Schema;

var UserSchema = new Schema({
    email: {
        type: String, required: true,
        trim: true, unique: true,
        match: /^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/
    },
    firstName: {type: String},
    lastName: {type: String}
});

mongoose.model('User', UserSchema);

Controller

import { mongoose } from "@dekproject/scope";
import "../model/users";

var User = mongoose.model("User");

export let createUser = (req, res) => {
    var user = new User(req.body);

    user.save(function (err) {
        if (err) res.status(500).send(err.message).end();
        else res.send(user).end();
    });
}

export let getAllUsers = (req, res) => {
    User.find(function (err, users) {
        if (err) res.status(500).send(err.message).end();
        else res.send(users).end();
    });
}

Route

import { createUser, getAllUsers } from "../controllers/users";

export default async (router) => {
    router.route('/users').post(createUser).get(getAllUsers);
}

Keywords

FAQs

Package last updated on 05 Oct 2020

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc