feat: 实现一些用户接口
This commit is contained in:
24
src/index.js
Normal file
24
src/index.js
Normal file
@@ -0,0 +1,24 @@
|
||||
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
|
||||
const DATABASE_URL = process.env.DATABASE_URL || "mongodb://localhost:27017/labplus"
|
||||
|
||||
mongoose.connect(DATABASE_URL)
|
||||
const db = mongoose.connection
|
||||
db.on("error", (error) => console.error(error))
|
||||
db.once("open", () => console.log("Connected to Database"))
|
||||
|
||||
app.use(Express.json())
|
||||
app.use(Express.urlencoded({ extended: true }))
|
||||
|
||||
app.use("/api", router)
|
||||
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Server running on http://localhost:${PORT}`)
|
||||
})
|
||||
Reference in New Issue
Block a user