forked from tannerdanger/ChatApp-WebService
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·45 lines (39 loc) · 1.67 KB
/
index.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
41
42
43
44
45
//express is the framework we're going to use to handle requests
const express = require('express');
//Create a new instance of express
const app = express();
// const bodyParser = require("body-parser");
// //This allows parsing of the body of POST requests, that are encoded in JSON
// app.use(bodyParser.json());
// app.use('/params', require('./routes/params.js'));
app.use('/#', require('./routes/#.js'));
app.use('/weather', require('./routes/weather.js'));
app.use('/register', require('./routes/register.js'));
/*
* Return HTML for the / end point.
* This is a nice location to document your web service API
* Create a web page in HTML/CSS and have this end point return it.
* Look up the node module 'fs' ex: require('fs');
*/
app.get("/", (req, res) => {
res.writeHead(200, {'Content-Type': 'text/html'});
for (i = 1; i < 7; i++) {
//write a response to the client
res.write('<h' + i + ' style="color:blue">Hello World!</h' + i + '>');
}
res.end(); //end the response
});
//
/*
* Heroku will assign a port you can use via the 'PORT' environment variable
* To accesss an environment variable, use process.env.<ENV>
* If there isn't an environment variable, process.env.PORT will be null (or undefined)
* If a value is 'falsy', i.e. null or undefined, javascript will evaluate the rest of the 'or'
* In this case, we assign the port to be 5000 if the PORT variable isn't set
* You can consider 'let port = process.env.PORT || 5000' to be equivalent to:
* let port; = process.env.PORT;
* if(port == null) {port = 5000}
*/
app.listen(process.env.PORT || 5000, () => {
console.log("Server up and running on port: " + (process.env.PORT || 5000));
});