[英]how to access an exported json object in node.js
Dopey question.愚蠢的问题。 I have an object from a library and I want to access it but I just don't get it.
我有一个来自图书馆的对象,我想访问它,但我就是没有得到它。 Here is the exported object:
这是导出的对象:
exports.listAccounts = function(successCallback,errorCallback) { var actionDescriptor = { method : "GET", module : "accounts", action : "accountlist", useJSON: true, }; this._run(actionDescriptor,{},successCallback,errorCallback); };
Now I want to access the account list in code at etListAccounts:现在我想在 etListAccounts 的代码中访问帐户列表:
//user sends confirmation code and we get acesss token app.get('/users/sendcode', function (req, res) { console.log('verification CODE is '+req.query.vCode); //end get verification code et.getAccessToken(req.query.vCode, function() { console.log('thread entered getAccessToken function') et.listAccounts( function(){console.log('account list success')}, function(error) { console.log("Error encountered while attempting " + "to retrieve account list: " + error); }); // console.log(accountlist[0]); }, function(error) { console.log("Error encountered while attempting " + "to exchange request token for access token: " + error); } ); })
I've tried this:我试过这个:
et.listAccounts( function(accountList){console.log('account list success')}, function(error) { console.log("Error encountered while attempting " + "to retrieve account list: " + error); });
And I've tried this:我试过这个:
et.listAccounts( function(){accountList}, function(error) { console.log("Error encountered while attempting " + "to retrieve account list: " + error); });
And I've tried this:我试过这个:
accountList - et.listAccounts( function(){console.log('account list success')}, function(error) { console.log("Error encountered while attempting " + "to retrieve account list: " + error); });
This is a nice simple question and I feel foolish for asking it but lots of people can answer it and lots of beginners will find it useful.这是一个很好的简单问题,我觉得问它很愚蠢,但很多人可以回答它,很多初学者会发现它很有用。
From the snippet you shared with us, it appears that you are not importing the module.从您与我们分享的片段来看,您似乎没有导入该模块。 Please read the documentation here:
请阅读此处的文档:
https://nodejs.org/docs/latest/api/modules.html#modules_accessing_the_main_module https://nodejs.org/docs/latest/api/modules.html#modules_accessing_the_main_module
var imported = require('nameOfModule');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.