I'm a bit new to JavaScript and I was wondering, how do I have a variable in my program persist after I turn off the program and turn it back on again.
For example, if I have:
//Call package
var Discord = require("discord.js");
var caterpieBot = new Discord.Client();
var nextClubMeeting;
//Listener Event for recieved messages
caterpieBot.on("message", message =>
{
var sender = message.author; // who sent the message
var msg = message.content.toUpperCase();
var prefix = "!" //command to interact with caterpieBot
var tempMsg = msg;
var splitMsg = tempMsg.split(":")
if(splitMsg[0] === "CATERPIE, PLEASE SCHEDULE OUR NEXT CLUB MEETING FOR")
{
message.channel.send("Yes " + sender + ", I will schedule the next club meeting for: " + splitMsg[1])
nextClubMeeting = splitMsg[1]; //I WANT "nextClubMeeting" TO //PERSIST ON RESTART!
}
And I have the user change that number to 2
when the program is running. When I restart the program if I tried to print userInputedNumber
it would return as undefined
. How would I have my program remember that userInputedNumber = 2
after it is restarted? (2
would be whatever number the user inputted).
Hm, you may need to setup a database to store that data. There are other ways of "persisting" data on the frontend where messages are being exchanged. Sessions are a looser way of doing so but this seems more of a user specific input related to that specific user. Perhaps you can route in MongoDB into your app and store it, and access it later whenever you need to?