Heroku can't find local module on heroku (Node.js)

express, heroku, javascript, node.js

Solution

Because you put the `config.js` file in your `.gitignore` it is not being pushed to the Heroku server, like you said you had intended. For what you say you want to do, you would typically use Heroku's config vars to set environment variables that are then read in by your application:

$ heroku config:add TWITTER_TOKEN=<token> TWITTER_SECRET=<secret>

Then in your `app.js` file you can access these environment variables with:

var token = process.env['TWITTER_TOKEN'];
var secret = process.env['TWITTER_SECRET'];

Problem

I'm working on a Node.js app, and am using a config.js file that exposes my twitter API tokens/secrets. I'm doing this because I plan on open-sourcing the application after I finish it, and would like to keep those private (and thus, have put that file in my `.gitignore`. Anyways, to my question - I'm getting the following error log: ``` 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 ``` My file name is `config.js`, and I am doing a: `var config = require('./config')` in my app. I don't have it listed as a dependency in my `package.json` file, since it's not in NPM. Running locally with foreman and the Procfile (like heroku's docs say to do) work great. But, I'm confused why it's giving me an error when I'm requiring a local file. `config.js` is in the same directory level as my `app.js` is, so the path to require it is correct. EDIT: Below is the portion of code I am using in `app.js`: ``` var express = require('express') , sys = require('sys') , request = require('request') , config = require('./config') ``` Thanks - Any help would be greatly appreciated!

Original source