Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
4
rated 0 times [  5] [ 1]  / answers: 1 / hits: 69436  / 12 Years ago, wed, january 2, 2013, 12:00:00

I want to render raw .html pages using Express 3 as follows:



server.get('/', function(req, res) {
res.render('login.html');
}


This is how I have configured the server to render raw HTML pages (inspired from this outdated question):



server
.set('view options', {layout: false})
.set('views', './../')
.engine('html', function(str, options) {
return function(locals) {
return str;
};
});


Unfortunately, with this configuration the page hangs and is never rendered properly. What have I done wrong? How can I render raw HTLM using Express 3 without fancy rendering engines such as Jade and EJS?


More From » node.js

 Answers
30

If you don't actually need to inject data into templates, the simplest solution in express is to use the static file server (express.static()).



However, if you still want to wire up the routes to the pages manually (eg your example mapping '/' to 'login.html'), you might try res.sendFile() to send your html docs over:



http://expressjs.com/api.html#res.sendfile


[#81134] Sunday, December 30, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jazminkyrap

Total Points: 631
Total Questions: 89
Total Answers: 109

Location: Finland
Member since Fri, Oct 21, 2022
2 Years ago
;