Sunday 23 December 2018

How to get data from another file?

So I have been searching over internet for more than an hour now but couldn't find a good answer and wanted to ask here as well. Please keep in mind I am fairly new with node.js.My problem is, I have one .js file that is a chatbot and actively listens user texts on the platform. And it checks "if message == some_pre_defined -> write pre_defined_response". Now I can do this and it works pretty well. However, I have the message / response list on the same .js file as well.What I want to achieve is, have two files, and keep commands/responses at one of them, and use the main one to call different functions. So, it would be like this,main.js -> functions/other stuffcommands.js ->const responseObject = { "ayy": "Ayy, lmao!", "wat": "Say what?", "lol": "roflmaotntpmp" }; Then I want to call that constant from my main file. Currently I have that command list in my main.js file, so I can call them & use them no problem. But, is there a way to call that variable from another file? I know that functions could be called with "require" but I haven't find a way to call that constant/variable from other file and use it actively.

Submitted December 23, 2018 at 04:03PM by nithronium

No comments:

Post a Comment