我正在开发一个 Node.js 应用程序,并且正在使用一个config.js文件来公开我的 twitter API 令牌/秘密。我这样做是因为我计划在完成应用程序后将其开源,并希望将其保密(因此,将该文件放在我的.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 中。
与工头和 Procfile 一起在本地运行(就像 heroku 的文档所说的那样)效果很好。但是,我很困惑为什么当我需要本地文件时它会给我一个错误。config.js
与我的目录位于同一目录级别app.js
,因此要求它的路径是正确的。
编辑:下面是我使用的代码部分app.js
:
var express = require('express')
, sys = require('sys')
, request = require('request')
, config = require('./config')
谢谢 - 任何帮助将不胜感激!