-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
39 lines (27 loc) · 785 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
29
30
31
32
33
34
35
36
37
38
39
// file structure
// server.js <--- this file
// db/
// config.js
// customer.js
// node_modules
// package.json
const express = require('express');
const db = require('./db/config');
const queryCustomer = require('./db/customer');
const app = express();
app.use(express.json());
const port = process.env.PORT || 3000;
// fetch all
app.get('/api/customers', queryCustomer.fetchAll);
// fetch by id
app.get('/api/customers/:id', queryCustomer.fetchById);
// create by id
app.post('/api/customers', queryCustomer.addNew);
// delete by id
app.delete('/api/customers/:id', queryCustomer.deleteById);
// put by id
app.put('/api/customers/:id', queryCustomer.updateById);
app.listen(port, () => {
console.log(`Server is running on port ${port}.`);
});
module.exports = app