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

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

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 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!