Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Ignore configuration files
config.json

# Logs
logs
*.log
Expand Down
88 changes: 44 additions & 44 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,65 @@
const http = require('http');
const hostname = 'localhost';
const port = 3000;
const fs = require('fs');
var config = {};
if (fs.existsSync('./config.json')) config = require('./config.json');
const hostname = config.hostname || 'localhost';
const port = config.port || 3005;

var friends = require("./friends.json"); // Once for all times

const server = http.createServer((request, response) => {
response.statusCode = 200;
response.setHeader('Content-type', 'text/html');
response.write(
'<!DOCTYPE html> \n' +
'<html lang="en"> \n' +
' <head> \n' +
' <meta charset="utf-8"> \n' +
' <meta http-equiv="X-UA-Compatible" content="IE=edge"> \n' +
' <meta name="viewport" content="width=device-width, initial-scale=1"> \n' +
' <meta name="description" content="Home Page"> \n' +
' <meta name="author" content="Carlos Arias"> \n' +
' <title>Netcentric Computing Home Page</title> \n' +
' <!-- Bootstrap core CSS --> \n' +
' <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">\n' +
' </head> \n' +
' <body> \n' +
' <div class="container" style="text-align: center"> \n' +
' <h1>Another Example of Node</h1><br> \n'

);
var currentDate = new Date();
response.write(
' <p>Current time is: ' + currentDate + '</p>'
);
response.write(
' <table class="table table-bordered table-hover"> \n' +
' <thead> \n' +
' <tr> \n' +
' <th scope="col">First Name</th> \n' +
' <th scope="col">Last Name</th> \n' +
' <th scope="col">Phone</th> \n' +
' </tr> \n' +
' </thead> \n' +
' <tbody> \n'
`<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Home Page">
<meta name="author" content="Michael Bryant">
<title>I Told You They're Not Imaginary!</title>
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
<div class="container" style="text-align: center">
<h1>A List of My Friends</h1>
<hr/>
<p>Current time is: ${currentDate}</p>
<table class="table table-bordered table-hover">
<thead>
<tr>
<th scope="col">First Name</th>
<th scope="col">Last Name</th>
<th scope="col">Phone</th>
<th scope="col">Gender</th>
</tr>
</thead>
<tbody>
`
);
for (var key in friends)
for (var f in friends[key])
response.write(
' <tr> \n' +
' <td>' + friends[key][f]["firstName"] + '</td> \n' +
' <td>' + friends[key][f]["lastName"] + '</td> \n' +
' <td>' + friends[key][f]["phone"] + '</td> \n' +
' </tr> \n'
` <tr>
<td>${friends[key][f]["firstName"]}</td>
<td>${friends[key][f]["lastName"]}
<td>${friends[key][f]["phone"]}
<td>${friends[key][f]["gender"]}
</tr>
`
);

response.write(
' </tbody> \n' +
' </table> \n'
);
response.write(
' </body> \n' +
'</html> \n'
` </tbody>
</table>
</body>
</html>`
);
response.end();

});

server.listen(port, hostname, () => {
Expand Down
71 changes: 71 additions & 0 deletions app2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
const http = require('http');
const fs = require('fs');
var config = {};
if (fs.existsSync('./config.json')) config = require('./config.json');
const hostname = config.hostname || 'localhost';
const port = config.port || 3005;

var friends = require("./friends2.json"); // Once for all times

const server = http.createServer((request, response) => {
response.statusCode = 200;
response.setHeader('Content-type', 'text/html');
var currentDate = new Date();
response.write(
`<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Home Page">
<meta name="author" content="Michael Bryant">
<title>I Told You They're Not Imaginary!</title>
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
<div class="container" style="text-align: center">
<h1>A List of My Friends</h1>
<hr/>
<p>Current time is: ${currentDate}</p>`
);
for (var key in friends) {
response.write(`
<h2>${key.toUpperCase()}</h2>
<table class="table table-bordered table-hover">
<thead>
<tr>
<th scope="col">First Name</th>
<th scope="col">Last Name</th>
<th scope="col">Phone</th>
</tr>
</thead>
<tbody>`
);
for (var f in friends[key]) {
response.write(
` <tr>
<td>${friends[key][f]["firstName"]}</td>
<td>${friends[key][f]["lastName"]}
<td>${friends[key][f]["phone"]}
</tr>
`
);
}
response.write(
` </tbody>
</table>`
);
}

response.write(
` </body>
</html>`
);
response.end();
});

server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
11 changes: 6 additions & 5 deletions friends.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{"friends": [
{"firstName": "George", "lastName": "Kristoferson", "phone": "2062062066"},
{"firstName": "Bill", "lastName": "Madison", "phone": "4254254255"},
{"firstName": "Peter", "lastName": "Frampton", "phone": "2125554545"},
{"firstName": "Anna", "lastName": "Calixtus", "phone": "7259865321"},
{"firstName": "Marie", "lastName": "Curie", "phone": "6017744991"}
{"firstName": "George", "lastName": "Kristoferson", "phone": "2062062066", "gender": "male"},
{"firstName": "Bill", "lastName": "Madison", "phone": "4254254255", "gender": "male"},
{"firstName": "Peter", "lastName": "Frampton", "phone": "2125554545", "gender": "male"},
{"firstName": "Anna", "lastName": "Calixtus", "phone": "7259865321", "gender": "female"},
{"firstName": "Marie", "lastName": "Curie", "phone": "6017744991", "gender": "female"},
{"firstName": "William", "lastName": "Churchil", "phone": "2021122333", "gender": "male"}
]}
12 changes: 12 additions & 0 deletions friends2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"boys": [
{"firstName": "George", "lastName": "Kristoferson", "phone": "2062062066"},
{"firstName": "Bill", "lastName": "Madison", "phone": "4254254255"},
{"firstName": "Peter", "lastName": "Frampton", "phone": "2125554545"},
{"firstName": "William", "lastName": "Churchil", "phone": "2021122333"}
],
"girls": [
{"firstName": "Anna", "lastName": "Calixtus", "phone": "7259865321"},
{"firstName": "Marie", "lastName": "Curie", "phone": "6017744991"}
]
}