-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
34 lines (26 loc) · 992 Bytes
/
app.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
30
31
32
33
34
const express = require('express')
const mongoose = require('mongoose')
const cors = require('cors');
const app = express();
// SETTING UP MIDDLEWARES
app.use(express.json())
app.use(express.urlencoded({extended:false}));
app.use(cors())
// IMPORTING ROUTES
const fishesRoute = require('./routes/fishes')
const ordersRoute = require('./routes/orders')
// HANDLING ROUTES
app.use('/fishes', fishesRoute);
app.use('/orders',ordersRoute)
require('dotenv').config() // importing all variables inside .env file into process.env object as property
// CONNECTING TO DATABASE
mongoose.connect(process.env.DATABASE,
{useNewUrlParser:true, useUnifiedTopology:true}, (err) => {
if(err) console.log(`DATABASE FAILED TO CONNECT! 🐛 ${err}`)
console.log(`🤩 database connected successfully!`)
})
// STARTING OUT SERVER
app.listen( process.env.PORT || 80 , (err) => {
if(err) console.log(`SERVER FAILED TO RUN 🐛 ${err}`)
console.log(`😎 server running successfully!`)
})