You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
729 B
JavaScript
38 lines
729 B
JavaScript
1 year ago
|
// Dependencies
|
||
|
const express = require("express")
|
||
|
const mongoose = require("mongoose")
|
||
|
const cors = require("cors")
|
||
|
require("dotenv").config()
|
||
|
const userRoute = require("./routes/user")
|
||
|
|
||
|
// Server start
|
||
|
const app = express()
|
||
|
|
||
|
// Middlewares
|
||
|
app.use(express.json())
|
||
|
app.use(express.urlencoded({ extended: true }))
|
||
|
|
||
|
app.use(cors())
|
||
|
|
||
|
//Database
|
||
|
mongoose
|
||
|
.connect(process.env.MONGO_URL, {
|
||
|
useNewUrlParser: true,
|
||
|
useUnifiedTopology: true,
|
||
|
dbName: "CSP2",
|
||
|
})
|
||
|
.then(() => {
|
||
|
console.log("Connected to Database..")
|
||
|
})
|
||
|
.catch((err) => {
|
||
|
console.log(err)
|
||
|
})
|
||
|
|
||
|
// Routes
|
||
|
app.use("/user", userRoute)
|
||
|
|
||
|
// Server up
|
||
|
app.listen(process.env.PORT || 3000, () => {
|
||
|
console.log(`Server is running on port ${process.env.PORT}..`)
|
||
|
})
|