-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathindex.js
More file actions
39 lines (29 loc) · 962 Bytes
/
index.js
File metadata and controls
39 lines (29 loc) · 962 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
35
36
37
38
39
// Require DOTENV to get ENV variable
require('dotenv').config();
const express = require('express');
const massive = require('massive');
// Controller File
const racerCtrl = require('./controllers/racer.controller');
// .ENV Variables
const {
CONNECTION_STRING
} = process.env;
// Setup App
const app = express();
// TLM
app.use(express.json());
// Database Connection
// massive will execute this connection upon every single start of the server
massive(CONNECTION_STRING).then((dbInstance) => {
// set the database instance to app
app.set('db', dbInstance);
// log to the console for successful connection
console.log('Database Connected!')
});
// End Points
app.get('/api/racers', racerCtrl.getRacers);
app.post('/api/racers', racerCtrl.addRacers);
app.put('/api/racers/:id', racerCtrl.updateRacer);
app.delete('/api/racers/:id', racerCtrl.deleteRacer);
// Server Listening
app.listen(8080, () => console.log('Server Running!'))