_getEmail() {
const emails = [];
return new Promise((resolve, reject) => {
this.start();
this.db.query('SELECT * FROM contacts', (err, res) => {
if (!!err) {
return reject('Error in the Query');
} else {
res.forEach(function (item, i) {
if ((item.email !== '') && (item.email !== null)) {
emails.push(item.email);
}
});
this.end();
return resolve(emails);
}
});
});
}
async getEmail(){
try {
const emails = await this._getEmail();
} catch (error) {
console.log(error);
};
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<textarea id="area" cols="100" rows="50"></textarea>
<script>
var doc = {
"_id": "5b1055bab772d4a8c93dc0cf",
"name": "sendPhotoRemovePush",
"titleEn": "Photo deleted (No face)",
"titleRu": "Фото удалено (Без лица)",
"bodyEn": "Upload your photo with a face. Your profile will be deleted with in 24 hours",
"bodyRu": "Загрузите своё фото с лицом. Ваш профиль будет удалён в течении 24 часа",
"sound": "obyjvlenie.mp3",
"createdAt": "2018-05-31T21:02:39.547Z",
"updatedAt": "2018-06-01T07:09:29.791Z"
}
area.value = JSON.stringify(doc, null, 4);
</script>
</body>
</html>
async (req, res) => {
try {
const categories = await categoryModel.find({});
const products = await productModel.find({});
const seasons = await seasonModel.find({});
const sizes = await sizeModel.find({});
return res.render("admin", { categories, products, seasons, sizes });
} catch (error) {
console.log(error);
return res.render('error');
};
}
async (req, res) => {
try {
const [categories, products, seasons, sizes] = await Promise.all([
categoryModel.find({}),
productModel.find({}),
seasonModel.find({}),
sizeModel.find({})
])
return res.render("admin", { categories, products, seasons, sizes });
} catch (error) {
console.log(error);
return res.render('error');
};
}
module.exports = async function имя1(params) {
try {
const response = await request(params);
let charset = [];
charset.name = response.data;
const charsetResult = await someFunc(charset);
if (charsetResult.value === undefined) {
charsetResult.value = 'PR10';
} else {
charsetResult.guild = charset.guild.name;
}
return charsetResult;
} catch (error) {
console.log(error);
};
}
router.post('/', async (ctx) => {
const user = await new Promise((resolve, reject) => {
passport.authenticate('local', (err, user) => {
if (err) return reject(err);
return resolve(user);
})
})
if (!user) {
ctx.render('/', { title: 'Авторизация', message: ctx.body });
} else {
const payload = {
id: user.id,
displayName: user.displayName,
email: user.email
};
const token = jwt.sign(payload, jwtsecret); //здесь создается JWT
ctx.body = { user: user.displayName, token: 'JWT ' + token };
ctx.redirect('/user');
}
});
router.get('/', (req, res) => {
Order.find()
.then(orders => {
res.render('user', {
username: req.user.username,
title: 'Главная страница',
order: orders
});
})
.catch(error => {
console.log(error);
})
/* Вариант с калбеком
Order.find((error, orders) => {
if (error) {
console.log(error);
}
res.render('user', {
username: req.user.username,
title: 'Главная страница',
order: orders
});
})*/
});
router.get('/', async (req, res) => {
try {
const orders = await Order.find();
res.render('user', {
username: req.user.username,
title: 'Главная страница',
order: orders
});
} catch (error) {
console.log(error);
}
});
loadData = () => {
var options = {
uri: 'http://fake-domen.com/...',
headers: {
'User-Agent': 'Request-Promise'
},
json: true // Automatically parses the JSON string in the response
};
return rp(options)
.then(function (repos) {
console.log(repos, 'repos');
return repos
})
.catch(function (err) {
// API call failed...
});
}
const func = require('./func);
func()
.then()