[英]How to make a variable global from inside a function node.js?
i am trying to make this snmp variable global so i can save it in my mongoose database but i can not get it working, i have tried to declaring it as global and the window.data way but does not want to console.log outside my function. 我正在尝试使此snmp变量成为全局变量,所以我可以将其保存在我的猫鼬数据库中,但我无法使其正常工作,我试图将其声明为global和window.data方式,但不想在我的外部进行console.log功能。 i am sure it is just a small thing but would greatly appreciate one of you guys taking a minute out of your day.
我相信这只是一件小事,但是非常感谢你们抽出一分钟的时间。
thanks in advance 提前致谢
session.get({ oid: [2, 8, 0] }, function(err, varbinds) {
var vb;
if (err) {
console.log(err);
} else {
vb = varbinds[0];
}
console.log('The system description is "' + vb.value + '"');
session.close();
});
You can use Node.js global variable like so: 您可以像这样使用Node.js全局变量:
GLOBAL.window = {}; // creates a global variable "window"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.