How to Keep the values of a variable, even when restarting the program, in Javascript

Asked

Viewed 212 times

-1

I have the following problems every time I create a Javascript program and declare the values of the variables, when restarting the program the value of the variable is lost. ex:

var usuario = {
      nome: "Eduardo Ribeiro";
      idade: 19 }

when restarting the program, (open and close) the values of the variables are lost, I kind of would have to add each value again, I wanted to know how I do not restart the values of the variables when closing the program, if the answer is long, could indicate me something so I can study, because I am beginner in the areá and could not find looking on the net...

  • Eduardo, have you ever thought about persisting these values?

  • For long answers, I suggest using a Broker message like Kafka. To keep the values saved from the variables, you can save them to the database and load them during server startup.

2 answers

0

0

You can use a library like the cacache to save information via value key. For example:

const cacache = require('cacache');

cacache.put('caminho-para-meu-arquivo', 'teste', '1');

And to read the start basic information by reading straight from cache:

cache.get('caminho-para-meu-arquivo', 'teste').then(console.log); // 1

Browser other questions tagged

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