[英]how to set a value forever in node js
I'm new in node js.我是节点 js 的新手。 I want to save an id in a global variable.
我想在全局变量中保存一个 id。 I need that in many functions.
我在许多功能中都需要它。 But when server restart the variable get empty.
但是当服务器重新启动时,变量变空。 Is there any way to save my required value for a long time even when server restart?
即使服务器重新启动,有没有办法长时间保存我所需的值?
You can store variables as environmental variables, so that they can load each time you restart your server.您可以将变量存储为环境变量,以便在您每次重新启动服务器时加载它们。 or you can have them in file system or in database.
或者您可以将它们放在文件系统或数据库中。
You can save the variable using Store-js
您可以使用
Store-js
保存变量
To save the value using store js npm install store-js;使用 store js npm install store-js 保存值;
import store from 'store-js'; store.set('variable', value);//for saving value store.get('variable');// for getting of the value
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.