const express = require("express")
const app = express()
const cors = require("cors")
const mongoose = require("mongoose")
const dotenv = require("dotenv")
dotenv.config()

const PORT = process.env.PORT
const MONGO = process.env.MONGO_UI

const UserRoutes = require("./src/routes/users.r")

app.use(cors())
app.use(express.json())
app.use("/api", UserRoutes)

mongoose.connect(MONGO)
    .then(() => console.log("Database Connected"))
    .catch((err) => console.log("Error to connect database", err))

app.get("/", async (req, res) => {
    res.send("Hii, I'm working here.!!!!")
})

app.listen(PORT, console.log(`Server is running at http://localhost:${PORT}`))