TypeError [ERR_INVALID_ARG_TYPE]:在快速后端

时间:2020-07-30 01:01:48

标签: javascript node.js express

我为我的应用开发了一个快速后端。将请求发布到我的应用程序路由后,我收到错误消息

“ TypeError [ERR_INVALID_ARG_TYPE]:”块“参数必须是以下之一 输入字符串或缓冲区。”

尝试通过请求路由访问功能时发生此错误。

这是代码

app.post('/api/orderEmail', (req, res) => {
  //TODO
  console.log('Backend breakpoint');
  console.log(req.body);
  sendEmail(req.body.mail, req.body.name, "thanks"); // function call that generates error
});

sendEmail的定义如下:

const sendEmail = (to, name, type) => {
      

    const smtpTransport = mailer.createTransport({
        service: "Gmail",
        auth: {
            user: "xxusernamexx",
            pass: "xxpasswordxx"
        }
    })

    const mail = getEmailData(to, name, type)

    smtpTransport.sendMail(mail, function(error, response) {
        console.log("sendmail breakpoint");
        if(error) {
            console.log(error)
        } else {
            console.log( " email sent successfully")
        }
        smtpTransport.close();
    })


}

0 个答案:

没有答案