Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

273
Visualizações
Config.js file cannot import variables

I am making a large config.js file for all my messages (Discord.js V12). It works fine and everything, until the message I am trying to send contains variables (I am just stepping over from the situation with all variables spread, to one file). Somehow, the command file imports the variables from config.js, but not the other way around. This leaves me in a very tricky spot, where the config.js file gets rendered pretty much useless (for my situation). I switched from an .ENV file to a .JS file, specifically so that (I thought) I can include variables in my external file. Here is an sample for a problem:

Old situation:

const randomnumber = 5;

message.channel.send(`Hello world! ${randomnumber}`);

New situation, which doesn't work at the moment:

const config = require("./../../Other/config.js");
const randomnumber = 5;

message.channel.send(config.messages.testmessage);

Here is a piece of config.js (the randomnumber variable doesn't work, which is my problem):

exports.messages = { 
  testmessage: `Hello world! ${randomnumber}`),
}

I think that it doesn't work if also place const randomnumber = 5 in the config.js file, since somethimes the value after const, also contains variables of previous constructed variables. Or maybe, it is possible, but I am not sure. So that's my question.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The randomnumber variable isn't shared between files, unless it is explicitly imported in the config.js. In order to use that variable, it either needs to be declared in the config.js:

const randomnumber = 100;

exports.messages = {
  testmessage: `hello world: ${randomnumber}`
}

or, it can be shared using node imports and exports:

exports.randomnumber = 100

config.js:

const { randomnumber } = require('./otherfile.js');

exports.messages = {
  testmessage: `hello world: ${randomnumber}`
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda