Last active
August 29, 2015 14:09
-
-
Save davidDuymelinck/d530d69a0b9220ac1231 to your computer and use it in GitHub Desktop.
Step by step creation of a node site
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Error 404</title> | |
</head> | |
<body> | |
<h1>Page not found</h1> | |
<p><a href="/">Home</a></p> | |
</body> | |
</html> |
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
var express = require('express'); | |
var app = express(); | |
var fs = require('fs'); | |
app.set('views', './'); | |
app.engine('html', function (filePath, options, callback) { | |
fs.readFile(filePath, function (err, content) { | |
if (err) throw new Error(err); | |
return callback(null, content.toString()); | |
}) | |
}); | |
app.set('view engine', 'html'); | |
app.get('/', function (req, res) { | |
res.render('index.html'); | |
}); | |
app.get('/page2', function (req, res) { | |
res.render('page2.html'); | |
}); | |
app.use(function(req, res) { | |
res.status(400); | |
res.render('404.html'); | |
}); | |
var server = app.listen(1337, '127.0.0.1', function () { | |
var host = server.address().address; | |
var port = server.address().port; | |
console.log('Example app listening at http://%s:%s', host, port); | |
}); |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Hello world</title> | |
</head> | |
<body> | |
<h1>Hello World</h1> | |
<p><a href="/page2">Page 2</a></p> | |
</body> | |
</html> |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>page 2</title> | |
</head> | |
<body> | |
<h1>Page 2</h1> | |
<p><a href="/">Home</a></p> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment