forked from longlife/labplus-server
链接数据库
This commit is contained in:
783
package-lock.json
generated
783
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -13,8 +13,8 @@
|
||||
"author": "hbk01",
|
||||
"license": "GPL-3.0-or-later",
|
||||
"dependencies": {
|
||||
"dotenv": "^16.3.1",
|
||||
"express": "^4.18.2",
|
||||
"mongoose": "^8.0.3"
|
||||
"mongoose": "^8.0.3",
|
||||
"nodemon": "^3.1.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,8 @@ module.exports = {
|
||||
env: {
|
||||
"NODE_ENV": "production",
|
||||
"PORT": 80,
|
||||
"DATABASE_URI": "mongodb://USERNAME:PASSWORD@localhost:27017",
|
||||
// TODO: change to your own username and password
|
||||
"DATABASE_URI": "mongodb://USERNAME:PASSWORD@localhost:27017/labplus",
|
||||
}
|
||||
}]
|
||||
}
|
||||
@@ -33,7 +33,8 @@ router.put("/:id", async (req, res) => {
|
||||
router.delete("/:id", async (req, res) => {
|
||||
const user = await User.findByIdAndDelete(req.params.id).then(() => {
|
||||
res.json({
|
||||
"message": "User deleted successfully"
|
||||
"message": "deleted successfully",
|
||||
user
|
||||
})
|
||||
}).catch((err) => {
|
||||
res.json({ error: err })
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
import Express from "express"
|
||||
import dotenv from "dotenv"
|
||||
import router from "./router.js"
|
||||
import mongoose from "mongoose"
|
||||
|
||||
dotenv.config()
|
||||
|
||||
const app = Express()
|
||||
const PORT = process.env.PORT || 8080
|
||||
|
||||
mongoose.connect(process.env.DATABASE_URI)
|
||||
const db = mongoose.connection
|
||||
|
||||
db.on("error", (error) => console.error(error))
|
||||
db.on("error", console.error.bind(console, "connection error:"))
|
||||
db.once("open", () => console.log("Connected to Database"))
|
||||
|
||||
app.use(Express.json())
|
||||
|
||||
Reference in New Issue
Block a user