Nodejs Express Loading HTML templates

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.