forked from DevMountain/node-3-afternoon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
38 lines (30 loc) · 1.01 KB
/
index.js
File metadata and controls
38 lines (30 loc) · 1.01 KB
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
const express = require('express');
const massive = require('massive');
const cors = require('cors');
const { json } = require('body-parser');
const { dbUser, dbPass } = require('./config');
const port = 3000;
const connectionString = `postgres://${dbUser}:${dbPass}@localhost/postgres`;
//<!=== App Declaration ===>
const app = express();
app.use(json());
app.use(cors());
//<!=== Invoke Massive ===>
const massiveConnection = massive(connectionString)
.then(dbInstance => {
app.set('db', dbInstance);
})
.catch(err => {
console.log(err);
});
//<!=== Controllers ===>
const products_controller = require('./products_controller');
//<!=== Endpoints ===>
app.get('/api/products', products_controller.getAll);
app.get('/api/product/:id', products_controller.getOne);
app.put('/api/product/:id', products_controller.update);
app.post('/api/product', products_controller.create);
app.delete('/api/product/:id', products_controller.delete);
app.listen(port, () => {
console.log(`Magic Happening on Port: ${port}`);
});