使用node.js, express和handlebars,我应该在哪里放置前端javascript

With node.js, express and handlebars, where should I place the front end javascript?

本文关键字:在哪里 我应该 前端 javascript handlebars node js express 使用      更新时间:2023-09-26

我已经按照这个教程建立了一个基本的快递应用与车把:http://code.tutsplus.com/tutorials/introduction-to-express--net-33367

现在我用不同的Highcharts做不同的页面;它们都有一个特定的前端javascript,必须放在head标签中。

我失去了应用程序的结构,这些前端脚本应该去我的mvc模式。如果它们是完全静态的,我想也许一些。js文件在我的公共文件夹,但也许我想动态地生成它们。例如,通过链接显示选项(颜色和东西)到用户帐户。有小费吗?

你试过这样设置吗?

模式:

<head>
    <script src="jquery.js"</script>
    <script src="highcharts.js"</script>
    <script src="{{chart}}"</script>
</head>

路由示例:

app.get('/home', function(req, res) {
    res.render('index',{chart:"myChart1.js"});
});