使用Node.js在html页面中打印变量

时间:2017-02-01 13:43:46

标签: html node.js variables

我的 app.js 中有一个变量,我想在我的HTML页面中将其打印出来,而不会激活页面的其他文本。

示例:

var test = 'hello';

我只想在 index.ejs 页面中打印hello

1 个答案:

答案 0 :(得分:2)

var test = 'hello'; 是您在app.js中声明的变量。您可以通过控制台以console.log(test)打印它。如果要在html模板中打印它,它必须是一个对象。 {test: 'hello'}可以在您的ejs html模板中打印为{{test}}。请查看ejs template engine.

的文档