-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
32 lines (27 loc) · 922 Bytes
/
index.js
File metadata and controls
32 lines (27 loc) · 922 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
30
31
32
const express = require("express");
const app = express();
app.get("/", (req, res) => {
res.send("Hello World!");
});
app.listen(8000, () => {
console.log("Example app listening on port 8000!");
});
//Load HTTP module
const http = require("http");
const hostname = "127.0.0.1";
const port = 3000;
//Create HTTP server and listen on port 3000 for requests
const server = http.createServer((req, res) => {
//Set the response HTTP header with HTTP status and Content type
res.statusCode = 200;
res.setHeader("Content-Type", "text/plain");
res.end("JavaScript\n");
});
//listen for request on port 3000, and as a callback function have the port listened on logged
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
app.set("port", process.env.PORT || 7000);
app.listen(app.get("port"), function() {
console.log("server started on port" + app.get);
});