- Use express preliminary framework
var exp = require('express'); var ejs = require('ejs'); var app = new exp(); app.set("view engine","ejs"); app.get('/index',function (req,res) { res.render ( ' tianwadi ' , {}); }); // default under, express views using .ejs files in directory app.listen(8888,'127.0.0.1');
- express and set the template directory template engine
var exp = require('express'); var ejs = require('ejs'); var app = new exp(); app.engine ( ' HTML ' , EJS .__ Express); // registration engine type defaults EJS App. SET ( ' View Engine ' , ' HTML ' ); // set the type of engine . App SET ( ' views ' , __ + dirname " / TPL " ); // custom template storage directory App. GET ( ' / index ' , function (REQ, RES) { res.render('index',{}); }); app.listen(8888,'127.0.0.1');
- The introduction of the resolution and static files
var exp = require('express'); var ejs = require('ejs'); var app = new exp(); app.use (exp. static ( ' static ' )); // specify static files in the root directory --- app.use also uses middleware app.engine ( ' HTML ' , EJS .__ Express); // registration engine type The default is EJS App. the sET ( ' View engine ' , ' HTML ' ); // set the engine type App. the sET ( ' views ' , __ dirname + " / tpl " ); // custom template directory where App. GET ( ' / index ',function (req,res) { res.render('index',{"headtitle":'ejs首页'}); }); app.listen(8888,'127.0.0.1');
html part
...... omitted parts <footer class = " footer Auto-Py-MT. 3 " > <div class="container"> <span class="text-muted">Place sticky footer content here.</span> </div> </footer> <script src="/js/jquery-3.4.1.min.js"></script></body> </html>
- Project Directory
- Static service hosting (to feel like a real pick up a static file 'Alias', url using aliases plus subordinate folders can access to resources)
var exp = require('express'); var ejs = require('ejs'); var app = new exp(); app.use (exp. static ( ' static ' )); // specify static files in the root directory app.use ( ' / Multimedia ' , exp. static ( ' static ' )); // true to the project folder from static the alias multimedia app.engine ( ' HTML ' , EJS .__ Express); // registration engine type defaults EJS App. SET ( ' View Engine ' , ' HTML ' ); // set the type of engine . App SET ( ' views ' , __ + dirname " / TPL " ); // custom template storage directory App. GET ( ' / index ' , function (REQ, RES) { res.render('index',{"headtitle":'ejs首页'}); }); app.listen(8888,'127.0.0.1');
html part
...... <div class="container"> <h1 class="mt-5"><%=headtitle%></h1> <p class="lead">Pin a footer to the bottom of the viewport in desktop browsers with this custom HTML and CSS. A fixed navbar has been added with <code>padding-top: 60px;</code> on the <code>main > .container</code>.</p> <p><img src="/multimedia/pic/EEhTIVVVUAAiht3.jpg" width="400"></p> <p>Back to <a href="/docs/4.3/examples/sticky-footer/">the default sticky footer</a> minus the navbar.</p> </div> ......