【发布时间】:2018-02-12 10:20:02
【问题描述】:
我根据环境有一个节点配置。 https://github.com/lorenwest/node-config
default.json
{
"server": {
"host": "localhost",
"protocol": "http",
"port": 9011
}
}
我想在<script> 标签内的index.html 中得到这个。有谁知道这样做的方法是什么?
我可以在下面的 js 文件中获取此配置
app.js
var config = require('config');
console.log(config.server.host);
【问题讨论】:
-
为什么需要这个?你想完成什么?
-
@FedericoklezCulloca 我在 index.html 中有另一个服务器的 url,到目前为止它是硬编码的。我希望它应该从配置文件中选择。它将请求从这台服务器发送到另一台服务器
-
您可以添加一个服务器端渲染工具...您使用的是什么堆栈?
-
我正在使用 nodejs ,表达框架。你说的“服务器端渲染工具”是什么意思?
标签: javascript node.js node-config