24 lines
645 B
JavaScript
24 lines
645 B
JavaScript
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}`)
|
|
}) |