-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
40 lines (31 loc) · 1 KB
/
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
40
'use strict';
// load dotenv to manage variables
require('dotenv').config();
// load express to do the heavy of the server
const express = require('express');
const app = express();
//establish the PORT number
const PORT = process.env.PORT || 3000;
//tell express where to load our "html files from"
app.use(express.static('./public'));
// creates routes (paths) that the user can access the server from
app.get('/hello', (request,response) =>{
response.status(200).send('Hello');
});
//load express to do the heavy of the server
app.get('/data', (request, response) => {
let airplanes = {
departure: Date.now(),
canFly: true,
pilot: 'Well Trained'
}
response.status(200).json(airplanes);
});
app.get('/', (request, response) => {
response.status(200).redirect('index.html');
});
//catchall to get routes that don't exist
app.use('*', (request, response) => response.send(`Sorry, that route does not exist`));
//Turn the surver on
app.listen(PORT, () => console.log (`Listening on ${PORT}`)
);