If I run my node.js script in the containing directory, it runs fine. If I run it from crontab with
*/1 * * * * /usr/local/bin/node /Users/full/path/to/main >> ~/mtf.log
I see errors relating to the twilio config
var TWClient = require('twilio')(configTwilio.accountSid, configTwilio.
^
TypeError: Cannot read property 'accountSid' of undefined
Why doesn't this work when run from cron? The same behaviour occurs on the server (ubuntu) and localhost (OSX 10.8.5)
Top of script (main.js)
var phantom = require('phantom');
var portscanner = require('portscanner');
var FeedParser = require('feedparser'),
request = require('request');
var configDB = require('config').DB;
var configTwilio = require('config').Twilio;
var mysql = require('mysql');
var TWClient = require('twilio')(configTwilio.accountSid, configTwilio.authToken);
The config file default.yaml is in the config directory relative to main.js and contains (redacted):
DB:
dbHost: localhost
dbPort: 3306
dbName: xxx
dbUser: xxx
dbPass: xxx
Twilio:
accountSid: AC8fxxxxxxxxd5f7aace47a8
authToken: d863b4ddfxxxxxx9b7c845
I've also tried this locally:
env -i sh -c 'cd /path/to/script && /usr/local/bin/node main'
but get:
events.js:72
throw er; // Unhandled 'error' event
^
Error: spawn ENOENT