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
129 changes: 129 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
console.log('Node works beautifully :) ')

// ------------------------------------------------------
// CHALK
// ------------------------------------------------------

/*
const chalk = require('chalk');

console.log(chalk.blue('Hello world!'));

console.log(chalk.blue.bgRed.bold('Hello world!'));

const error = chalk.bold.red;
const warning = chalk.keyword('orange');

console.log(error('Error!'));
console.log(warning('Warning!'));
*/

// ------------------------------------------------------
// FAKER ACTIVITY
// ------------------------------------------------------

/*
var faker = require('faker');

for (let i = 0; i< 10; i++) {
console.log( faker.commerce.productName() , faker.commerce.price())
}
*/

// ------------------------------------------------------
// CREATING A SERVER IN NODE
// ------------------------------------------------------

/*
const http = require('http');

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((req, res) => {
res.statusCode = 404;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World');
});

server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
*/

// ------------------------------------------------------
// EXPRESS
// ------------------------------------------------------


const express = require('express')
const app = express()
app.use((req, res, next) => {
console.log('In the middleware! ')
next()
})

app.use( express.static(__dirname + '/public') )
app.get('/' , ( req, res ) => {
res.sendFile(__dirname + '/views/home.html')
})


app.get('/about' , ( req, res ) => {
res.sendFile(__dirname + '/views/about.html')
})


app.get('/about/:user', (req, res) => {
res.send('Works ' + req.params.user)
})


app.get('/works', (ihreq, ihres) => {
ihres.sendFile(__dirname + '/views/works.html')
})

app.get('/gallery' , ( req, res ) => {
res.sendFile(__dirname + '/views/gallery.html')
})

app.get('/:user', (req, res) => {
const {user, age} = req.params
res.send('Hey '+ user + ' ' + age)
})

app.get('/', (req, res) => {
res.send("Hi there, welcome to my assignment!")
})


app.get('/speak/:animal', (req, res) => {
const {animal} = req.params

switch( animal ) {
case 'pig':
res.send("The pig says 'Oink!'")
break;
case 'dog':
res.send("The dog says 'Woff Woof!'")
break;
case 'cow':
res.send("The cow says 'Moo'")
break;
}
})

app.get('/greet/:text/:num', (req, res) => {
const {text, num} = req.params
res.send( (text + ' ').repeat(num) )
})

app.get('*', (req, res) => {
res.send("Sorry, page not found...Blame our developer")
})

app.use((req, res) => {
res.send("Sorry, page not found...Blame our developer")
})

app.listen(3000)
15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "lab-express-basic",
"version": "1.0.0",
"description": "<img src=\"https://imgur.com/XOS1Vdh.png\" width=\"150px\" height=\"150px\">",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.18.2"
}
}
Binary file added public/images/hawking1.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/hawking2.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/hawking3.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/hawking4.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions public/stylesheets/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
body{
background-color: #fff;

}
35 changes: 35 additions & 0 deletions views/about.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!-- about.html -->

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>About Stephen Hawking</title>
<link rel="stylesheet" href="/css/styles.css">
</head>
<body>
<header>
<h1>About Stephen Hawking</h1>
<nav>
<ul>
<li><a href="/">Home</a></li>
<li><a href="/about">About</a></li>
<li><a href="/works">Works</a></li>
<li><a href="/gallery">Gallery</a></li>
</ul>
</nav>
</header>
<main>
<section>
<h2>Biography</h2>
<p>Stephen William Hawking was an English theoretical physicist, cosmologist, and author. He was born on January 8, 1942, in Oxford, England. Despite being diagnosed with amyotrophic lateral sclerosis (ALS) at a young age, Hawking made significant contributions to the field of theoretical physics and cosmology.</p>
<p>His groundbreaking work on black holes, the nature of time, and the universe's origin earned him numerous awards and honors, including the Presidential Medal of Freedom, the Albert Einstein Medal, and the Fundamental Physics Prize.</p>
<img src="/public/images/hawking3.jpeg" alt="black hole" height="500" width="500"/>
</section>
</main>
<footer>
<p>&copy; 2024 Stephen Hawking Website. All rights reserved.</p>
</footer>
</body>
</html>
38 changes: 38 additions & 0 deletions views/gallery.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!-- gallery.html -->

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Stephen Hawking Gallery</title>
<link rel="stylesheet" href="/css/styles.css">
</head>
<body>
<header>
<h1>Stephen Hawking Gallery</h1>
<nav>
<ul>
<li><a href="/">Home</a></li>
<li><a href="/about">About</a></li>
<li><a href="/works">Works</a></li>
<li><a href="/gallery">Gallery</a></li>
</ul>
</nav>
</header>
<main>
<section>
<h2>Gallery</h2>
<div class="gallery">
<img src="/public/images/hawking1.jpeg" alt="Stephen Hawking 1">
</div>
<div class="gallery">
<img src="/public/images/hawking2.jpeg" alt="Stephen Hawking 2">
</div>
</section>
</main>
<footer>
<p>&copy; 2024 Stephen Hawking Website. All rights reserved.</p>
</footer>
</body>
</html>
34 changes: 34 additions & 0 deletions views/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!-- home.html -->

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Stephen Hawking</title>
<link rel="stylesheet" href="/css/styles.css">
</head>
<body>
<header>
<h1>Stephen Hawking</h1>
<nav>
<ul>
<li><a href="/">Home</a></li>
<li><a href="/about">About</a></li>
<li><a href="/works">Works</a></li>
<li><a href="/gallery">Gallery</a></li>
</ul>
</nav>
</header>
<main>
<section>
<h2>Welcome to the Stephen Hawking Website</h2>
<p>Explore the life, achievements, and contributions of one of the most brilliant minds of our time.</p>
<img src="/public/images/hawking4.jpeg" alt="Theory of Everything"/>
</section>
</main>
<footer>
<p>&copy; 2024 Stephen Hawking Website. All rights reserved.</p>
</footer>
</body>
</html>
37 changes: 37 additions & 0 deletions views/works.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!-- works.html -->

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Stephen Hawking's Works</title>
<link rel="stylesheet" href="/css/styles.css">
</head>
<body>
<header>
<h1>Stephen Hawking's Works</h1>
<nav>
<ul>
<li><a href="/">Home</a></li>
<li><a href="/about">About</a></li>
<li><a href="/works">Works</a></li>
<li><a href="/gallery">Gallery</a></li>
</ul>
</nav>
</header>
<main>
<section>
<h2>Selected Works</h2>
<ul>
<li><strong>A Brief History of Time:</strong> Hawking's best-selling book on cosmology, explaining complex scientific concepts to a general audience.</li>
<li><strong>The Universe in a Nutshell:</strong> A follow-up to "A Brief History of Time," delving deeper into the mysteries of the universe.</li>
<li><strong>Black Holes and Baby Universes and Other Essays:</strong> A collection of essays exploring various topics in physics and cosmology.</li>
</ul>
</section>
</main>
<footer>
<p>&copy; 2024 Stephen Hawking Website. All rights reserved.</p>
</footer>
</body>
</html>