Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

389
Vistas
How to resolve error: Missing the environment variable 'TWITTER_CONSUMER_KEY'

I am a beginnner in programming so least expect I will encounter any error ahead. This day, coded some Node.js application to post Twitter Feeds to Discord but fail to do so.

I can't figure out why I am seeing this error although I've already supplied the .env file with necessary data. Already run the necessary dependencies likes, npm install gm, npm i dotenv. Code is below.

'use strict';

const fs = require('fs');
const commandExistsSync = require('command-exists').sync;
const logger = require('./bin/logger');
const { version } = require('./package.json');

logger.info(`Starting the twitter-to-discord application v${version}`);

// Extract all the env variables we will be using
const {
  TWITTER_CONSUMER_KEYS,
  TWITTER_CONSUMER_SECRET,
  TWITTER_ACCESS_TOKEN_KEY,
  TWITTER_ACCESS_TOKEN_SECRET,
  MONGO_URI,
  DISCORD_BOT_TOKEN,
  DISCORD_CMD_PREFIX,
  DISCORD_BOT_OWNER_ID,
  TEMP,
} = process.env;

// Exit if the env variable was not set or passed. None can be empty
function envTest(value, name) {
  logger.debug(`${name}=${value}`);
  if (!value) {
    logger.error(`Missing the environment variable '${name}'`);
    process.exit(1);
  }
}

envTest(TWITTER_CONSUMER_KEYS, 'TWITTER_CONSUMER_KEYS');
envTest(TWITTER_CONSUMER_SECRET, 'TWITTER_CONSUMER_SECRET');
envTest(TWITTER_ACCESS_TOKEN_KEY, 'TWITTER_ACCESS_TOKEN_KEY');
envTest(TWITTER_ACCESS_TOKEN_SECRET, 'TWITTER_ACCESS_TOKEN_SECRET');
envTest(MONGO_URI, 'MONGO_URI');
envTest(DISCORD_BOT_TOKEN, 'DISCORD_BOT_TOKEN');
envTest(DISCORD_CMD_PREFIX, 'DISCORD_CMD_PREFIX');
envTest(DISCORD_BOT_OWNER_ID, 'DISCORD_BOT_OWNER_ID');
envTest(TEMP, 'TEMP');

// Ensure we can access the temp directory
try {
  fs.accessSync(process.env.TEMP, fs.constants.F_OK);
} catch (err) {
  logger.error(`Unable to access the temp directory: ${process.env.TEMP}`);
  logger.debug(err);
  process.exit(1);
}

// Ensure all the commands we need to function exist via PATH
if (!commandExistsSync('ffmpeg')) {
  logger.error('\'ffmpeg\' is not available on the command line');
  process.exit(1);
}
if (!commandExistsSync('gm')) {
  logger.error('\'gm\' is not available on the command line');
  process.exit(1);
}

// Passed all the startup tests
// Continue to load application
require('./bin');

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Even though you have installed dotenv, you didn't run it. You should have require('dotenv').config() at the start of your program.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda