T
T
TheBeJIIHiu2022-03-07 08:00:59
Node.js
TheBeJIIHiu, 2022-03-07 08:00:59

Why does it return ReferenceError: body is not defined?

const request = require("prequest")
const token = "СЕКРЕТ"
module.exports = (id) => {
  request("https://api.vk.com/method/users.get?token="+token+"&user_ids="+id+"&v=5.131", (error, response, body) => {
    console.log(body)
  })
  return body
}


Why is ReferenceError returned: body is not defined

Help, thanks in advance)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
defriz, 2022-03-07
@defriz

try another library like axios

const axios = require("axios");
const token = "СЕКРЕТ";
module.exports = (id) => {
  axios.post("https://api.vk.com/method/users.get", {
  params: {
      'token': token,
      'user_ids': id,
      'v': '5.131'
  }
}).then((res) => { console.log(res) /* или console.log(res.data), чтобы вывести ответ от ВК */  }).catch((err) => { console.log(err) });
};

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question