diff --git a/ex5-serverExpress.js b/ex5-serverExpress.js index dab6ede..e136cb6 100644 --- a/ex5-serverExpress.js +++ b/ex5-serverExpress.js @@ -1,14 +1,17 @@ // Use NPM to install expressjs -//npm install express +/* npm install express + * In case it breaks, choose an earlier version, like: + * npm install express@4.8.5 + */ // Set express module to variable "express" -var express = require('express'); +var express = require("express"); // Create an "app" variable from the express library var app = express(); // Add a "route" that leads to the req/res, as seen in Node.js -app.get('/', function(req, res){ +app.get("/", function(req, res){ res.send("Express powered web page"); }); diff --git a/ex6-routesServer.js b/ex6-routesServer.js index a5273e9..429940d 100644 --- a/ex6-routesServer.js +++ b/ex6-routesServer.js @@ -1,2 +1,42 @@ -// Outputs "Hello World" to the console -console.log("Hello World"); \ No newline at end of file +// Express makes routes easy + +// Set express module to variable "express" +var express = require("express"); + +// Create an "app" variable from the express library +var app = express(); + +// Add a "route" that leads to the req/res, as seen in Node.js +app.get("/", function(req, res){ + res.send("Express powered web page"); +}); + +// Second route to /page +app.get("/page", function(req, res){ + res.send("This is a second page"); +}); + +// This page returns a JSON value, the standard Javascript data sructure +app.get("/json", function(req, res){ + res.json( + { + "message": "welcome to the page" + } + ) +}); + +// Visit page with value set +// /info?value=my value +app.get("/info", function(req, res){ + res.send("The info you sent is: " + req.query.value); +}); + +// This page is requires a post call: such as from a web frm +app.post("/form", function(req, res){ + res.send("The form value is: " + req.query.value); +}); + +// Starts up the server +var server = app.listen(1337, function() { + +}); \ No newline at end of file diff --git a/ex7-staticFolder.js b/ex7-staticFolder.js index a5273e9..3ae658b 100644 --- a/ex7-staticFolder.js +++ b/ex7-staticFolder.js @@ -1,2 +1,21 @@ -// Outputs "Hello World" to the console -console.log("Hello World"); \ No newline at end of file +// Express makes routes easy + +// Set express module to variable "express" +var express = require("express"); + +// Create an "app" variable from the express library +var app = express(); + +// Sets the /static webpage route to the /public folder +app.use('/static', express.static(__dirname + '/public')); + +// Add a "route" that leads to the req/res, as seen in Node.js +app.get("/", function(req, res){ + // Grab a file and respond with that + res.sendFile(__dirname + '/public/index.html'); +}); + +// Starts up the server +var server = app.listen(1337, function() { + +}); \ No newline at end of file diff --git a/ex10-johnny5.js b/exA-johnny5.js similarity index 100% rename from ex10-johnny5.js rename to exA-johnny5.js diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..54c1360 --- /dev/null +++ b/public/index.html @@ -0,0 +1,16 @@ + + + + + + + Example Web Page + + +

My Webpage

+

Here it is

+ + + Makerbar picture + + \ No newline at end of file diff --git a/public/makerbar.jpg b/public/makerbar.jpg new file mode 100644 index 0000000..b6cfdb5 Binary files /dev/null and b/public/makerbar.jpg differ