Heroku无法在heroku(Node.js)上find本地模块
我正在做一个Node.js应用程序,并使用一个公开我的twitter API令牌/秘密的config.js文件。 我这样做是因为我计划在完成应用程序后开放源代码,并且希望保留这些私有的(因此已经把这个文件放在我的.gitignore
。
反正,对我的问题 – 我得到以下错误日志:
2012-04-09T22:41:12+00:00 app[web.1]: node.js:134 2012-04-09T22:41:12+00:00 app[web.1]: ^ 2012-04-09T22:41:12+00:00 app[web.1]: throw e; // process.nextTick error, or 'error' event on first tick 2012-04-09T22:41:12+00:00 app[web.1]: Error: Cannot find module './config' 2012-04-09T22:41:12+00:00 app[web.1]: at require (module.js:348:19) 2012-04-09T22:41:12+00:00 app[web.1]: at Function._load (module.js:266:25) 2012-04-09T22:41:12+00:00 app[web.1]: at Function._resolveFilename (module.js:320:11) 2012-04-09T22:41:12+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:6:19) 2012-04-09T22:41:12+00:00 app[web.1]: at Module._compile (module.js:404:26) 2012-04-09T22:41:12+00:00 app[web.1]: at Object..js (module.js:410:10) 2012-04-09T22:41:12+00:00 app[web.1]: at Function._load (module.js:297:12) 2012-04-09T22:41:12+00:00 app[web.1]: at EventEmitter._tickCallback (node.js:126:26) 2012-04-09T22:41:12+00:00 app[web.1]: at Module.load (module.js:336:31) 2012-04-09T22:41:12+00:00 app[web.1]: at Array.<anonymous> (module.js:423:10) 2012-04-09T22:41:13+00:00 heroku[web.1]: State changed from starting to crashed 2012-04-09T22:41:13+00:00 heroku[web.1]: Process exited with status 1
我的文件名是config.js
,我正在做我的应用程序中的var config = require('./config')
。 我没有列在我的package.json
文件中的依赖项,因为它不在NPM中。
与领class和Procfile本地运行(如heroku的文档说)做的很好。 但是,我很困惑,为什么当我需要一个本地文件时,它给了我一个错误。 config.js
与我的app.js
位于相同的目录级别,所以要求它的path是正确的。
编辑 :下面是我在app.js
使用的代码部分:
var express = require('express') , sys = require('sys') , request = require('request') , config = require('./config')
谢谢 – 任何帮助将不胜感激!
因为你把config.js
文件放在你的.gitignore
文件里,所以不会被推送到Heroku服务器,就像你说的那样。 对于你所说的你想要做的事情,你通常会使用Heroku的config vars来设置环境variables,然后由你的应用程序读入:
$ heroku config:add TWITTER_TOKEN=<token> TWITTER_SECRET=<secret>
然后在您的app.js
文件中,您可以通过以下方式访问这些环境variables:
var token = process.env['TWITTER_TOKEN']; var secret = process.env['TWITTER_SECRET'];