diff --git a/.gitignore b/.gitignore index 496ee2c..8776b15 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ -.DS_Store \ No newline at end of file +.DS_Store +package-lock.json +examples/node_modules/ +gordonramsay/node_modules \ No newline at end of file diff --git a/examples/hello.js b/examples/hello.js new file mode 100644 index 0000000..b8c57fe --- /dev/null +++ b/examples/hello.js @@ -0,0 +1 @@ +console.log("Hello World") \ No newline at end of file diff --git a/examples/package.json b/examples/package.json new file mode 100644 index 0000000..35da9a7 --- /dev/null +++ b/examples/package.json @@ -0,0 +1,14 @@ +{ + "name": "examples", + "version": "0.1.0", + "description": "Starting off with express", + "main": "server.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "anton.a.egorov@durham.ac.uk", + "license": "ISC", + "dependencies": { + "express": "^4.18.2" + } +} diff --git a/examples/server.js b/examples/server.js new file mode 100644 index 0000000..aa1ad3a --- /dev/null +++ b/examples/server.js @@ -0,0 +1,26 @@ +const express = require('express') +const app = express() + +app.get('/', function(req, resp){ + resp.send('Hello everybody'); +}) + +app.get('/bob/b', function(req, resp){ + resp.send('Hello builder'); +}) + +app.get('/random/:max', function(req, resp){ + max = parseInt(req.params.max) + rand = Math.floor(Math.random()*max) +1 + console.log('Max via url is ' + max + ' rand is ' + rand) + resp.send('' + rand) +}) + +app.get('/r', function(req, resp){ + max = parseInt(req.query.max) + rand = Math.floor(Math.random()*max) +1 + console.log('Max via query is ' + max + ' rand is ' + rand) + resp.send('' + rand) + }) + +app.listen(8090) \ No newline at end of file diff --git a/examples/webserver.js b/examples/webserver.js new file mode 100644 index 0000000..adaf720 --- /dev/null +++ b/examples/webserver.js @@ -0,0 +1,8 @@ +http = require("http") + +http.createServer(function (request, response) { + response.writeHead(200, ); + response.end('Hello World\n'); +}).listen(8080); + +console.log('Server running at http://127.0.0.1:8080/'); \ No newline at end of file diff --git a/gordonramsay/index.html b/gordonramsay/index.html index 4b34351..18757f3 100644 --- a/gordonramsay/index.html +++ b/gordonramsay/index.html @@ -94,7 +94,7 @@

Gordon Ramsay

Played Aussie football for St Kilda

- Picture of the wrong Gordon Ramsay +
Download examples
diff --git a/gordonramsay/package.json b/gordonramsay/package.json new file mode 100644 index 0000000..2495044 --- /dev/null +++ b/gordonramsay/package.json @@ -0,0 +1,16 @@ +{ + "name": "gordonramsay", + "version": "0.1.0", + "description": "Aussie sportsperson", + "main": "server.js", + "scripts": { + "start": "nodemon server.js", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "express": "^4.18.2", + "nodemon": "^3.0.1" + } +} diff --git a/gordonramsay/server.js b/gordonramsay/server.js new file mode 100644 index 0000000..df7f6f8 --- /dev/null +++ b/gordonramsay/server.js @@ -0,0 +1,24 @@ +const express = require('express'); +const app = express(); + +let facts = [ + {"text": "He played for St. Kilda", "tags": ["geography", "history"]}, + {"text": "Was born in 1929", "tags": ["history"]}, + {"text": "Is not famous for cookery", "tags": ["friday"]} +]; + +app.get("/fact", function(request, response){ + let factNo = parseInt(request.query.n); + response.send(facts[factNo].text); +}); + +app.get("/tags", function(request, response){ + let tags = []; + for(let fact of facts){ + tags = tags.concat(fact.tags) + } + let tagSet = new Set(tags); + response.send([...tagSet]) +}) + +app.listen(8090); \ No newline at end of file