Node rendering HTML template Configuration

Source: Internet
Author: User

Node rendering HTML template Configuration installation Swig module
NPM Install Swig--save-dev

Loading the Swig module

var swig = require ('swig');

Template configuration

//first parameter: The name of the template engine, which is also the suffix of the template file, and the second method of parsing the template contentApp.engine ('HTML', swig.renderfile);//set the file directory, the first parameter must be the views, the second parameter is a directoryApp.Set('View Engine','HTML');//canceling the template cache during developmentSwig.setdefaults ({cache:false });//bodyparser SettingsApp.use (bodyparser.urlencoded ({extended:true}));

Rendering in Routing

// renders the router in the route . Get ('/', function (req, res, next) {  res.render ('index ' );});

Node rendering HTML template Configuration

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.