Nodejs+Express生成的项目,将jade模板引擎改为html模板

// 1.server文件夹下安装ejs模块
npm install ejs --save




// 2.app.js文件中新增代码;
var ejs = require('ejs');
...
app.engine('.html', ejs.__express);
app.set('view engine', 'html');




// 3.views文件夹下删除原来以.jade结尾的文件,新建index.html
// index.html代码如下:
<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <h1>Hello, Express is very Good!</h1>
</body>
</html>




// 4.启动文件
node bin/www


//5.浏览器中输入http://localhost:3000/

猜你喜欢

转载自blog.csdn.net/qq_25479327/article/details/80569672