Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

express 笔记 #7

Open
meahu opened this issue Apr 30, 2019 · 0 comments
Open

express 笔记 #7

meahu opened this issue Apr 30, 2019 · 0 comments

Comments

@meahu
Copy link
Owner

meahu commented Apr 30, 2019

引入 html 模板的方式:

app.get('/', (req, res, next) => {
    let temp = fs.readFileSync('./index.html', {encoding: 'utf8'});
    res.send(temp);
});

引入 ejs 模板的方式

app.set('view engine', 'ejs'); // 设置使用的模版引擎:ejs 【测试了一下,这一步不用也可以】
app.set('views', path.join(__dirname, 'views')); // ejs 模板位置,不设置的话,默认目录是 views
app.get('/', (req, res, next) => {
    res.render('index.ejs', {title: '首页'}); // index.ejs 要放到 views
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant