Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

272
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!