Функция не возвращает массив NodeJS
Есть скрипт getPopularProduct.js
В нём получаю и парсю json
// получение списка популярных товаров
const request = require('request');
var rp = require('request-promise');
function first() {
var options = {
uri: 'https://www.pantus.ru/api/rest/2.0/popular/',
qs: {
},
headers: {
'User-Agent': 'Request-Promise'
},
json: true // Automatically parses the JSON string in the response
};
rp(options)
.then(function (data) {
var popularIdArray = [];
for (var id in data.data) {
popularIdArray.push(data.data[id].id);
}
console.log(popularIdArray); //выводит спарсенные айдишники
return popularIdArray; // !!! undefined !!!
})
.catch(function (err) {
// API call failed...
// return undefined;
});
}
module.exports = first;
Передаю через return массив в другой скрипт
const jsonResponse = require('../DB/remote/methods-api/getPopularProduct')
function getList() {
console.log("My Arr "+jsonResponse());
}
module.exports = getList;
выводит: My Arr undefined
Что не так?
Пробовал осюда по-разному, нода ругается или один фиг андефаинд.