-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
29 lines (22 loc) · 825 Bytes
/
server.js
File metadata and controls
29 lines (22 loc) · 825 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
const express = require('express');
const app = express();
const cors = require('cors');
const nutrients = require('./data');
require('dotenv').config();
app.use(cors());
app.use(express.static('public'));
//No longer needed with above code, all static files are already included from public folder
// app.get('/', (request, response) => {
// response.sendFile(__dirname + '/index.html');
// })
app.get('/api', (request, response) => {
response.json(nutrients);
});
app.get('/api/:nutrient', (request, response) => {
const nutrientName = request.params.nutrient.toLowerCase();
nutrients[nutrientName] ? response.json(nutrients[nutrientName]) :
response.json(nutrients['unknown']);
});
app.listen(process.env.PORT, ()=> {
console.log(`The server is now running on port ${process.env.PORT}`);
})