-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
85 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 [email protected] | ||
*/ | ||
|
||
// 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"); | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,42 @@ | ||
// Outputs "Hello World" to the console | ||
console.log("Hello World"); | ||
// 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() { | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,21 @@ | ||
// Outputs "Hello World" to the console | ||
console.log("Hello World"); | ||
// 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() { | ||
|
||
}); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!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"> | ||
<title>Example Web Page</title> | ||
</head> | ||
<body> | ||
<h1>My Webpage</h1> | ||
<p>Here it is</p> | ||
|
||
<!--- Note that /static is used, even if the picture is in /public ---> | ||
<img src="/static/makerbar.jpg" alt="Makerbar picture"> | ||
</body> | ||
</html> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.