How to order file from another folder and run it Javascript

Asked

Viewed 340 times

-1

I’m making a bot for Discord, there is a folder called Commands, I wonder what I call the files of this folder in my main file, bot.js and run them

  • I didn’t even come to this post, I didn’t understand his answer

1 answer

1

meu-app
   |--bot.js // Arquivo principal
   |--commands // Pasta com os comandos que serão executados no arquivo bot.js
     |--index.js

// commands/index.js

module.exports = function check() { 
    return "Estou sendo executado de dentro da pasta commands." 
}

Since the bot.js file and the Commands folder are at the same directory level, to call the index.js file that is inside the Commands folder, in the bot.js file use the require command to call the files from the Commands folder.

// bot.js
const check = require('./commands');
console.log(check());
// Estou sendo executado de dentro da pasta commands.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.