Using the Express framework in Nodejs, she defaults to the Ejs and jade rendering templates. Since I used to think her code writing style is very uncomfortable or want to write in the form of HTML, so I looked for the use of HTML template.
Directly on the code, the main is in
App.engine ('. html ', ejs.__express); App.set (' View engine ', ' html ');
these two sentences.
1 varHTTP = require (' http '),2Express = require (' Express '),3FS = require (' FS '),4Ejs = require (' Ejs ')),5Path = require (' path '),6ZMQ = require (' ZMQ '),//http://zeromq.org/7Msgpack = require (' Msgpack ');//Decompression Module8 varApp =Express ();9App.set (' Port ', Process.env.PORT | | 1235);TenApp.set (' views ', __dirname + '/sunxu/views '); OneApp.engine ('. html '), ejs.__express); AApp.set (' View engine ', ' HTML '); - - App.use (Express.favicon ()); theApp.use (Express.logger (' Dev '))); - App.use (Express.bodyparser ()); - App.use (Express.methodoverride ()); - App.use (app.router); +App.use (Express.static (Path.join (__dirname, ' sunxu/public ')))); - + A if(' development ' = = App.get (' env '))) { at App.use (Express.errorhandler ()); - } -App.get ('/',function(req, res) { -Res.render (' index ', {title: ' Paint title '}); - }); -App.get ('/users ',function(req, res) { inRes.render (' users ', {title: ' Users member '}); - }); to + varHttp_server = Http.createserver (APP). Listen (App.get (' Port '),function(){ -Console.log (' Express server listening on port ' + app.get (' Port '))); the});//creating a server listener
Reference article: http://blog.sina.com.cn/s/blog_a0cc1c0b0101dp6i.html
Nodejs Express Loading HTML templates