Skip to content

Instantly share code, notes, and snippets.

@kevinchisholm
Last active January 7, 2018 19:54
Show Gist options
  • Save kevinchisholm/5e41fc0ad0c180aac5ed3145a2133c81 to your computer and use it in GitHub Desktop.
Save kevinchisholm/5e41fc0ad0c180aac5ed3145a2133c81 to your computer and use it in GitHub Desktop.
//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');
});
//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');
});
//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');
});
{
"dependencies": {
"express": "4.14.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment