因此我正在执行heroku页面上的'getting started'过程。heroku node.js教程 - 将env变量发送到其他js页面
通过克隆他们的教程回购,我决定添加我自己的index.html
和app.js
文件到他们已经为我创建的/public
文件夹中。
目录如下:
node-getting-started repo folder
| node_modules folder
| public folder
| | app.js
| | index.html
| index.js
| package.json
| Procfile
的package.json
的main
点index.js
看起来像这样:
index.js
var express = require('express');
var app = express();
app.set('port', (process.env.PORT || 5000));
app.use(express.static(__dirname + '/public'));
app.get('/', function(request, response) {
var obj = { ... };
var secret_key = process.env.SECRET_KEY;
// what should i do here to send the variables above to my app.js file?
// response.send(secret_key) ???
});
app.listen(app.get('port'), function() {
console.log('Node app is running on port', app.get('port'));
});
在这一点上,是什么我试图做的是在内发送我的app.js
文件,所以我可以在那里使用它。
这是正确的方式去做这件事吗?有没有其他的(适当的?)方式发送到其他文件?
我基本上想要做同样的事情与环境变量,如在index.js
设置var secret_key = process.env.SECRET_KEY
并发送到app.js
,以便我也可以在那里使用它。
有人可以向我解释我该如何去做这件事?