Consumer key for Twit config isn't recognized



I’m brand new to all this so apologies if this isn’t the right place to post, but I’m working on a NodeJS app using Twit.

This is what I have in the beginning where I declare my variables:

var Twit = require('twit');
var twitter = new Twit({

when I try to run it, I get this message:

“Error: Twit config must include consumer_key when using user auth.”

I have doubled checked my keys, they are all correct. I’m not sure what I’m doing wrong. Any help is greatly appreciated. Thank you!


I am facing the same problem.
Though, I resolved this using redis
Put twitter variables into .env file

Back in the root of your project, create a file called .env. This will be used to store our local configuration variables that we will access from our code. Paste the following stub into the .env file and fill in the values.


Going through the trouble of hiding our secrets in .env doesn’t do us any good if we publish the file to github. So open .gitignore and add the following line:


Example -
This is in the main.js file -

var redis = require('redis');
var T = new Twit({
    consumer_key: process.env.TWITTER_CONSUMER_KEY,
    consumer_secret: process.env.TWITTER_CONSUMER_SECRET,
    access_token: process.env.TWITTER_ACCESS_TOKEN,
    access_token_secret: process.env.TWITTER_ACCESS_SECRET


Actually, now I have resolved the issue by, inserting the keys directly to the Twin();

Hope, this will help you!

var Twit = require('twit')
var T = new Twit({
  consumer_key:         '...',
  consumer_secret:      '...',
  access_token:         '...',
  access_token_secret:  '...',
  timeout_ms:           60*1000,  // optional HTTP request timeout to apply to all requests.