mongoose-backpack
Advanced tools
Comparing version 0.2.1 to 0.2.2
@@ -38,17 +38,2 @@ ``` | ||
// Define a route for the "hello world" message | ||
app.get("/subject", async (req, res) => { | ||
try { | ||
// Create a new message document | ||
const newMessage = new Message({ message: "Hello world!" }); | ||
await newMessage.save(); | ||
// Return the message document as JSON | ||
res.json(newMessage); | ||
} catch (err) { | ||
console.error(err); | ||
res.status(500).json({ message: "Internal server error" }); | ||
} | ||
}); | ||
// Start the Express app | ||
@@ -55,0 +40,0 @@ const port = process.env.PORT || 3000; |
{ | ||
"name": "mongoose-backpack", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -53,15 +53,43 @@ ``` | ||
const express = require("express"); | ||
const router = express.Router(); | ||
const User = require("../models/user"); | ||
const authRoutes = require("./moduleRoute/auth"); | ||
const mongoose = require("mongoose"); | ||
const { mongooseRouteName } = require("mongoose-backpack"); | ||
// auth routes | ||
router.use("/", authRoutes); | ||
// Create a new Express app | ||
const app = express(); | ||
// Mount the router for the "people" route | ||
router.use("/people", mongooseRouteName("people", User)); | ||
// Connect to the MongoDB Atlas cluster | ||
mongoose | ||
.connect( | ||
"mongodb+srv://fluxe0074:fluxe0074@cluster1.48j1fuf.mongodb.net/test", | ||
{ | ||
useNewUrlParser: true, | ||
useUnifiedTopology: true, | ||
} | ||
) | ||
.then(() => { | ||
console.log("Connected to MongoDB Atlas"); | ||
}) | ||
.catch((err) => { | ||
console.error("Error connecting to MongoDB Atlas", err); | ||
}); | ||
module.exports = router; | ||
// 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("/", mongooseRouteName("people", Message)); | ||
// Start the Express app | ||
const port = process.env.PORT || 3000; | ||
app.listen(port, () => { | ||
console.log(`Server started on port ${port}`); | ||
}); | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6284
94