diff --git a/app.js b/app.js index e69de29..18e958a 100644 --- a/app.js +++ b/app.js @@ -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) \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..a54d916 --- /dev/null +++ b/package.json @@ -0,0 +1,15 @@ +{ + "name": "lab-express-basic", + "version": "1.0.0", + "description": "", + "main": "app.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "express": "^4.18.2" + } +} diff --git a/public/images/hawking1.jpeg b/public/images/hawking1.jpeg new file mode 100644 index 0000000..639085c Binary files /dev/null and b/public/images/hawking1.jpeg differ diff --git a/public/images/hawking2.jpeg b/public/images/hawking2.jpeg new file mode 100644 index 0000000..e22e5c2 Binary files /dev/null and b/public/images/hawking2.jpeg differ diff --git a/public/images/hawking3.jpeg b/public/images/hawking3.jpeg new file mode 100644 index 0000000..01fa1d0 Binary files /dev/null and b/public/images/hawking3.jpeg differ diff --git a/public/images/hawking4.jpeg b/public/images/hawking4.jpeg new file mode 100644 index 0000000..6c60c12 Binary files /dev/null and b/public/images/hawking4.jpeg differ diff --git a/public/stylesheets/style.css b/public/stylesheets/style.css new file mode 100644 index 0000000..cd98292 --- /dev/null +++ b/public/stylesheets/style.css @@ -0,0 +1,4 @@ +body{ + background-color: #fff; + +} \ No newline at end of file diff --git a/views/about.html b/views/about.html new file mode 100644 index 0000000..f5d8231 --- /dev/null +++ b/views/about.html @@ -0,0 +1,35 @@ + + + + + + + + About Stephen Hawking + + + +
+

About Stephen Hawking

+ +
+
+
+

Biography

+

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.

+

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.

+ black hole +
+
+ + + diff --git a/views/gallery.html b/views/gallery.html new file mode 100644 index 0000000..ee6a974 --- /dev/null +++ b/views/gallery.html @@ -0,0 +1,38 @@ + + + + + + + + Stephen Hawking Gallery + + + +
+

Stephen Hawking Gallery

+ +
+
+
+

Gallery

+ + +
+
+ + + diff --git a/views/home.html b/views/home.html new file mode 100644 index 0000000..0051492 --- /dev/null +++ b/views/home.html @@ -0,0 +1,34 @@ + + + + + + + + Stephen Hawking + + + +
+

Stephen Hawking

+ +
+
+
+

Welcome to the Stephen Hawking Website

+

Explore the life, achievements, and contributions of one of the most brilliant minds of our time.

+ Theory of Everything +
+
+ + + diff --git a/views/works.html b/views/works.html new file mode 100644 index 0000000..adefc71 --- /dev/null +++ b/views/works.html @@ -0,0 +1,37 @@ + + + + + + + + Stephen Hawking's Works + + + +
+

Stephen Hawking's Works

+ +
+
+
+

Selected Works

+ +
+
+ + +