Last active
January 7, 2018 19:54
-
-
Save kevinchisholm/5e41fc0ad0c180aac5ed3145a2133c81 to your computer and use it in GitHub Desktop.
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
//reuire the express nodejs module | |
var express = require('express'), | |
//set an instance of exress | |
app = express(); | |
//for any requests to the root of the application | |
app.get('/', function (req, res) { | |
//construct the HTML that we will return | |
var HTML = '' | |
+ '<!DOCTYPE html>' | |
+ '<html>' | |
+ '<head>' | |
+ '<meta charset=utf-8>' | |
+ '<title>Express.js example</title>' | |
+ '</head>' | |
+ '<body>' | |
+ '<h1>This is example # 1</h1>' | |
+ '</body>' | |
+ '</html>'; | |
//rethrn the HTML to the user's browser | |
res.send(HTML); | |
}); | |
//wait for a connection | |
app.listen(3000, function () { | |
console.log('Server is running. Point your browser to: http://localhost:3000'); | |
}); |
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
//reuire the express nodejs module | |
var express = require('express'), | |
//set an instance of exress | |
app = express(), | |
//reuire the path nodejs module | |
path = require("path"); | |
//tell express that www is the root of our public web folder | |
app.use(express.static(path.join(__dirname, 'www'))); | |
//wait for a connection | |
app.listen(3000, function () { | |
console.log('Server is running. Point your browser to: http://localhost:3000'); | |
}); |
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
//reuire the express nodejs module | |
var express = require('express'), | |
//set an instance of exress | |
app = express(), | |
//reuire the path nodejs module | |
path = require("path"); | |
//tell express that www is the root of our public web folder | |
app.use(express.static(path.join(__dirname, 'www'))); | |
//tell express what to do when the /about route is requested | |
app.get('/about',function(req,res){ | |
res.sendFile(path.join(__dirname + '/www/about.html')); | |
}); | |
//wait for a connection | |
app.listen(3000, function () { | |
console.log('Server is running. Point your browser to: http://localhost:3000'); | |
}); |
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
{ | |
"dependencies": { | |
"express": "4.14.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment