'use strict';
// The Cloud Functions for Firebase SDK to create Cloud Functions and setup triggers.
const functions = require('firebase-functions');
// The Firebase Admin SDK to access the Firebase Realtime Database.
const admin = require('firebase-admin');
const nodemailer = require('nodemailer');
const mailTransport = nodemailer.createTransport({
service: 'gmail',
auth: {
user: "myemailid@gmail.com",
pass: "dssacdas324g",
},
});
// Your company name to include in the emails
// TODO: Change this to your app or company name to customize the email sent.
const APP_NAME = 'Cloud Storage for Firebase quickstart';
admin.initializeApp();
exports.sendOrdEmail = functions.database.ref('/shop_orders/{uid}/{pushid}')
.onCreate((snapshot, context) => {
const mailOptions = {
from: `app name <noreply@firebase.com>`,
to: "myvendor@gmail.com",
};
// The user subscribed to the newsletter.
mailOptions.subject = `Welcome to app name!`;
mailOptions.text = `Hey aisha! Welcome to app name. I hope you will enjoy our service.`;
await mailTransport.sendMail(mailOptions);
console.log('New welcome email sent to:', "myvendor@gmail.com");
return 200;
});
错误
sudo firebase deploy --only功能
===部署到“项目名称” ...
i部署功能运行命令:npm --prefix“ $ RESOURCE_DIR” 运行皮棉
functions @ lint / project / mydir / functions 护送。
/project/mydir/functions/index.js 34:9错误解析 错误:意外的令牌mailTransport
✖1个问题(1个错误,0个警告)
npm错误!代码ELIFECYCLE npm ERR! errno 1 npm错误!功能@棉绒:
eslint .
npm错误!退出状态1 npm ERR! npm ERR!失败于 functions @ lint脚本。 npm ERR!这可能不是问题 npm。上面可能还有其他日志记录输出。npm错误!有关此运行的完整日志,请参见:npm ERR!
/home/midhilaj/.npm/_logs/2019-03-25T08_59_43_803Z-debug.log错误:函数预部署错误:命令以非零终止 退出代码1
答案 0 :(得分:2)
在sendOrdEmail
函数内部,您尝试使用关键字await
,但是该函数未声明为async
。
您需要将函数定义行更改为:
exports.sendOrdEmail = functions.database.ref('/shop_orders/{uid}/{pushid}')
.onCreate(async (snapshot, context) => {
您还需要确保使用NodeJS 8运行时来支持此关键字。