Hello, made the implementation of the method that works with the expectation of an event into a separate module. During page rendering, this method is called to get the parameters. Parameters are not returned. How to properly organize this task in my case?
index.js
var vk = require('./lib/vk.js'); app.get('/vk', function(req, res) { res.render('home',{ vk: vk.getMessages('wall.get', {'owner_id' : 456475864535})}); }); vk.js
var VK = require('vksdk'); var vk = new VK({ 'appId': 5364746354, 'appSecret': 'fxgdhfdfs', 'language': 'ru' }); exports.getMessages = function (req,params) { vk.setSecureRequests(true); vk.request(req,params); vk.on('done:wall.get', function (_o) { return "privet"; // даже это не выводит console.log(JSON.stringify(_o, null, 4)); return _o; }); };
returnHowever, in reality, the problem is asynchronous: you have a res.render called before the vk.request request arrives. You need to pass the callback togetMessages, call it inside thedone:wall.gethandlerdone:wall.get, and callres.render()- Yaant already in it