-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
56 lines (43 loc) · 1.8 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// We first require our express package
var express = require('express');
var bodyParser = require('body-parser');
var myData = require('./data.js');
// This package exports the function to create an express instance:
var app = express();
// We can setup Jade now!
app.set('view engine', 'ejs');
// This is called 'adding middleware', or things that will help parse your request
app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({extended: true})); // for parsing application/x-www-form-urlencoded
// This middleware will activate for every request we make to
// any path starting with /assets;
// it will check the 'static' folder for matching files
app.use('/assets', express.static('static'));
// Setup your routes here!
app.get("/manual-dom", function (request, response) {
response.render("pages/manual-dom");
});
app.get("/jquery-dom", function (request, response) {
response.render("pages/jquery-dom");
});
app.get("/the-window", function (request, response) {
response.render("pages/the-window");
});
app.get("/location", function (request, response) {
response.render("pages/location");
});
app.get("/localstorage", function (request, response) {
response.render("pages/localstorage");
});
app.get("/form-validation", function (request, response) {
response.render("pages/form-validation");
});
app.get("/", function (request, response) {
// We have to pass a second parameter to specify the root directory
// __dirname is a global variable representing the file directory you are currently in
response.sendFile("./pages/index.html", {root: __dirname});
});
// We can now navigate to localhost:3000
app.listen(3000, function () {
console.log('Your server is now listening on port 3000! Navigate to http://localhost:3000 to access it');
});