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

224
Visualizações
How to export an object from a .js file to use it in main file

I have 2 files: bot.js and queue.js In the second file i define a variable called queue using this code:

const { google } = require("googleapis");
const play = require('play-dl');
const lista = []

module.exports = { lista }

module.exports = {...
}

In the first file i try to import the object with this code:

require(`./commands/queue.js`)
console.log(lista)

But when And i would like to be able to use its content in the first file How can i do that? I've seen other answers and tried their methods but couldn't make it work

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

0

Ensure you export the object, then require it by deconstructing from the exports

Queue.js

const { google } = require("googleapis");
const play = require('play-dl');
const lista = []

module.exports = {
   lista
}

Bot.js

const { lista } = require('path-to-queuejs-here');

console.log(lista)
// []
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