Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
389 views
in Technique[技术] by (71.8m points)

node.js - Using HTML in Express instead of Jade

How to I get rid of Jade while using Express with Node.JS? I want to just use plain html. In other articles I have seen that people recommended app.register() which is now deprecated in the latest version.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can do it this way:

  1. Install ejs:

    npm install ejs
    
  2. Set your template engine in app.js as ejs

    // app.js
    app.engine('html', require('ejs').renderFile);
    app.set('view engine', 'html');
    
  3. Now in your route file you can assign template variables

    // ./routes/index.js
    exports.index = function(req, res){
    res.render('index', { title: 'ejs' });};
    
  4. Then you can create your html view in /views directory.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

Just Browsing Browsing

[4] html - How to create even cell spacing within a

2.1m questions

2.1m answers

60 comments

56.9k users

...