-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
28 lines (23 loc) · 805 Bytes
/
server.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
// Imports
if(process.env.NODE_ENV !== 'production'){
require('dotenv').config()
}
const express = require('express')
const mongoose = require('mongoose')
// Import API Routes
const notificationRoutes = require('./routes/api/notifications');
// Create an instance of express app
const app = express()
// Set port
const port = process.env.PORT || '3000'
// Connect to MongoDB
mongoose.connect(process.env.DATABASE_URL, { useNewUrlParser: true, useUnifiedTopology: true })
const db = mongoose.connection
db.on('error', (error) => console.error(error))
db.once('open', () => console.log('[STATUS] Connected to Database'))
// Register API Routes
app.use('/notification', notificationRoutes);
// Listen app on given port
app.listen(port, () => {
console.info(`[STATUS] App listening on port ${port}`)
})