Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
946 B
2
Indexable
Never
const express = require("express")
const mongoose = require("mongoose")
//const userRoutes = require("./routes/user")

const MONGODB_URI = process.env.MONGODB_URI || "mongodb://127.0.0.1:27017/jswdcoder";

const app = express()
const port = 4001

mongoose.connect(MONGODB_URI, {
    useNewUrlParser : true,
    useUnifiedTopology : true
})

mongoose.connection.on('connected', () => {
    console.log("DB is connected")
})

mongoose.connection.on('error', (err) => {
    console.log(`DB Connection error ${err}`)
})

app.use(express.json());

//app.use("/users",userRoutes)

app.get("/", (req, res) => {
    res.send("hello world");

})

app.get("/api", (req, res) => {
     //let request = req.body   
     res.send(`request`)
})

mongoose.connect(MONGODB_URI).then((success)=> console.log("Connected successfully")).catch((error) => console.log(error));

app.listen(4001, () => {
    console.log(`server started on http://localhost:${port}`)
})