simplest way to have Express serve a default page?
I looked briefly for the best practices for serving a public folder and specifying the default page to serve. After reviewing the 'Express middleware' documentation, my solution looks like the following,
var express = require('express');
var app = express();
var options = {
index: "coming-soon.html"
};
app.use('/', express.static('app', options));
var server = app.listen(8081, function () {
var host = server.address().address;
var port = server.address().port;
console.log('my app is listening at http://%s:%s', host, port);
});
It's weird that no one mentioned redirection.
app.get('/', function(req, res){
res.redirect('/default.html');
});
This -of course- assumes that you have your 'default.html' at the public path. You can set your public path by using:
app.use(express.static(relative_path_to_project_root));
You could do something like this. Assuming its an html file that is relative to the .js file:
app.get('/', function(req, res){
res.sendfile('default.html', { root: __dirname + "/relative_path_of_file" } );
});