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

mongoose-backpack

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose-backpack

``` const mongoose = require("mongoose"); const Schema = mongoose.Schema;

  • 0.2.7
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source
const mongoose = require("mongoose");
const Schema = mongoose.Schema;

// ...

const { appendParams } = require("mongoose-backpack");

// ...
// ...

const userSchema = new Schema(
  {
    first_name: {
      type: String,
      required: true,
    },
    last_name: {
      type: String,
      required: true,
    },
    email: {
      type: String,
      required: true,
    },
    // ...
    // ...
  },
  { timestamps: true }
);

// ...
// ...

appendData = {
  id: function () {
    return this._id;
  },
  full_name: function () {
    return this.first_name + " " + this.last_name;
  },
};
appendParams(userSchema, appendData);

// ...
// ...

module.exports = mongoose.model("User", userSchema);
const express = require("express");
const mongoose = require("mongoose");
const { mongooseRouteName } = require("mongoose-backpack");

// Create a new Express app
const app = express();

// Connect to the MongoDB Atlas cluster
mongoose
  .connect(
    "mongodb+srv://jaykumargohil:#####@jkgmongo.9bdgpey.mongodb.net/demo",
    {
      useNewUrlParser: true,
      useUnifiedTopology: true,
    }
  )
  .then(() => {
    console.log("Connected to MongoDB Atlas");
  })
  .catch((err) => {
    console.error("Error connecting to MongoDB Atlas", err);
  });

// Define a schema for the "message" collection
const messageSchema = new mongoose.Schema({
  name: { type: String, required: true },
  message: { type: String, required: true },
  image: { type: String, required: false },
  file: { type: String, required: false },
});

// Create a model for the "message" collection
const Message = mongoose.model("Message", messageSchema);

app.use("/api", mongooseRouteName("people", Message));

// Start the Express app
const port = process.env.PORT || 3002;
app.listen(port, () => {
  console.log(`Server started on port ${port}`);
});

Keywords

FAQs

Package last updated on 04 May 2023

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