0

I'm trying to build a Telegram bot, I'm using the following npm package: https://www.npmjs.com/package/node-telegram-bot-api

I have the following project structure:

project structure

In my app.js file I do: const bot = new TelegramBot(token, {polling: true});. I would like to share this bot instance with the index.js files, so that in the index.js files I can do something like:

bot.onText(/\/time (.+)/, (msg, match) => {

});

I'm not sure how I can acomplish this, the only way I can think of is doing this by using module.exports on app.js file, but I'm not sure if that is the correct way of doing it.

-edit-

In the app.js file I want to do:

require('./plugins/time')
require('./plugins/weather')

and then type node app.js to run the bot.

1 Answers1

0

Yes, this is the correct way. The usual one.

Also there is global variables but they are evil, so you shouldn't use them.

Simply export your variable through exports.

Artsiom Miksiuk
  • 3,896
  • 9
  • 33
  • 49