-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
29 lines (24 loc) · 863 Bytes
/
index.js
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
29
require('dotenv').config()
const express = require('express')
const mongoose = require('mongoose')
const cors = require('cors')
const fileupload = require('express-fileupload')
const apiRoutes = require('./src/routes')
mongoose.connect(process.env.DATABASE, {
useNewUrlParser: true
});
mongoose.Promise = global.Promise;
mongoose.connection.on('error',(error)=>{
console.log("Error",error.message)
})
mongoose.connection.once('open', () => console.log("MongoDB connected: "+process.env.DATABASE));
const server = express()
server.use(cors())
server.use(express.json())
server.use(express.urlencoded({extended: true}))
server.use(fileupload())
server.use(express.static(__dirname+'/public'))
server.use('/',apiRoutes)
server.listen(process.env.PORT, ()=>{
console.log("server is running at port: "+process.env.PORT)
})