0
我是JavaScript新手。我有使用sendgrid發送電子郵件的簡單模塊:如何在javascript中使模塊異步
// using SendGrid's v3 Node.js Library
// https://github.com/sendgrid/sendgrid-nodejs
var helper = require('sendgrid').mail;
var fromEmail = new helper.Email('[email protected]');
var toEmail = new helper.Email('[email protected]');
var subject = 'Sending with SendGrid is Fun';
var content = new helper.Content('text/plain', 'and easy to do anywhere, even with Node.js');
var mail = new helper.Mail(fromEmail, subject, toEmail, content);
var sg = require('sendgrid')("**********************");
var request = sg.emptyRequest({
method: 'POST',
path: '/v3/mail/send',
body: mail.toJSON()
});
sg.API(request, function (error, response) {
if (error) {
console.log('Error response received');
}
console.log(response.statusCode);
console.log(response.body);
console.log(response.headers);
});
現在我想以異步方式調用此模塊。我應該實現承諾還是使用異步,等待?
順便說一句,你發佈你的API密鑰,我會盡快無效。 – usandfriends
刪除它並沒有幫助。它仍然可見 – baao
setTimeout()應該工作。 – TGarrett