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

202
Views
How to import a function in javascript?

I am currently coding a Discord bot in JS with Node.js and I wanted to write the commands code in a file for each command. All of these files are in a commands folder. Here is my code : in index.js :

const help = require("./commands/help.js")
help.help()

and in help.js :

function help() {
    const embed = new Discord.MessageEmbed()
        .setColor("#0099ff")
        .setTitle("Commandes du serveur")
        .addField("&help", "Commandes du bot")
        .addField("&youtube", "Lien vers la chaîne YouTube d'ANGI49")
        .addField("&twitch", "Lien vers la chaîne Twitch d'ANGI49")
        .setFooter("Bot développé par ANGI498045 et ywalt.js")

    message.reply({ embeds: [embed]});
}
module.exports()

The import never works and i have a module not found error Thanks

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

For a CommonJS module that uses require() (there two different module types in nodejs), in help.js, change this:

module.exports()

to this:

module.exports.help = help;

Then, you should be able to do this:

const help = require("./commands/help.js")
help.help()

As long as the "./commands/help.js" path is correct.

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!