-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
34 lines (24 loc) · 1016 Bytes
/
server.js
File metadata and controls
34 lines (24 loc) · 1016 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
29
30
31
32
33
34
//add dependencies that were added in the package.json file
const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const items =require('./routes/api/items');
const accounts =require('./routes/api/accounts');
const app=express();
//Body Parser Middleware
app.use(bodyParser.json());
//Mongo DB can be utilized from mlab.com -> Mongo DB Hosting
//Config File Abstraction
const db= require('./config/keys').mongoURI;
//Connect to Mongo Database
mongoose
.connect(db)
.then(()=>console.log('Mongo Database Successfully connected!'))
.catch(err=> console.log(err));
//use Routes for DB manipulation --> refer to items
app.use('/api/items',items);
//use Routes for DB manipulation --> refer to accounts
app.use('/api/accounts',accounts);
//Declare port for server -> environment variable or port 5000, allow server to listen on that port
const port=process.env.PORT || 5000;
app.listen(port, ()=>console.log(`Server Started on port ${port}`));