JS文件到HTML文件中的变量

时间:2018-11-14 21:06:37

标签: javascript html node.js

我有一个带有数组的JS文件,而我正试图将该数组粘贴为html文件,以便我可以使用它获取元素。问题是即时通讯使用节点来编写页面。有人有想法么?我已经检查了几页,但似乎找不到解决方法。

{'image1.jpeg','image2.jpeg','image3.jpeg','image4.jpeg'}

到html文件

app.get('/',function(req,res){
  res.sendFile(path.join(__dirname+'/index.html'));
  app.use(express.static(__dirname));
});

app.listen(3000);

1 个答案:

答案 0 :(得分:0)

您将需要使用templates with express

使用哈巴狗进来

模板:

html
  head
    title= title
  body
    h1= message

Express应用程序:

app.set('view engine', 'pug')
app.get('/', function (req, res) {
  res.render('index', { title: 'Hey', message: 'Hello there!' })
})