-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
28 lines (23 loc) · 783 Bytes
/
Copy pathindex.js
File metadata and controls
28 lines (23 loc) · 783 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const express= require('express')
const app=express()
const mongoose= require("mongoose")
const Fawn=require("fawn")
//import the mongo database uri connection defined in keys file
const {MONGO_URI} = require('./keys')
const PORT = process.env.PORT||5000;
//routes defined
const apiRoutes = require("./routes/api-routes")
//database connection
mongoose.connect(MONGO_URI, { useNewUrlParser: true ,useUnifiedTopology: true})
const db = mongoose.connection
db.on('error', (error) => console.error(error))
db.once('open', () => console.log('connected to database'))
app.use(express.json())
//start server on port
app.listen(PORT,()=>{
console.log('Connected to Server ',PORT)
})
//routes
app.use('/api',apiRoutes)
//initialize the mongoose tasks in fawn
Fawn.init(mongoose)