function funcname (){
request('https://site.ru', function (error, response, body) {
return body;
});
}
var info = funcname();
function getSome() {
return new Promise((resolve, reject) => {
request('https://site.ru', function (err, res, body) {
if (err) {
reject(err);
return;
}
resolve(body);
});
});
}
getSome().then(res => {
// do something with res
}).catch(err => {
// handle error
});
async foo() => {
const some = await getSome();
// use some
}
const rp = require('request-promise');
const getSome = async () => {
try {
const body = await rp({ uri: 'https://site.ru', json: true });
// do something other
return body;
} catch (err) {
// handle error
return err;
}
}
getSome().then(res => {
// do something with res
}).catch(err => {
// handle error
});
async foo() => {
const some = await getSome();
// use some
}