Skip to content

Instantly share code, notes, and snippets.

@paduc
Created September 1, 2011 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paduc/1186498 to your computer and use it in GitHub Desktop.
Save paduc/1186498 to your computer and use it in GitHub Desktop.
How to serve a static html file with Express. Anyone have something better?
app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(__dirname + '/public'));
app.set("view options", {layout: false});
// make a custom html template
app.register('.html', {
compile: function(str, options){
return function(locals){
return str;
};
}
});
});
app.get('/', function(req, res){
res.render('index.html');
});
@paduc
Copy link
Author

paduc commented Sep 2, 2011

I wonder if this would work as well:

app.get('/', function (req, res) {
res.sendfile(__dirname + '/index.html');
});

@paduc
Copy link
Author

paduc commented Sep 2, 2011

Yes it does work. That was easy!

@nuweb
Copy link

nuweb commented Jan 18, 2013

But, it's not serving the css/js/images. How can we also serve them without 404s?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment