问题:[ERR_INVALID_ARG_TYPE]:“侦听器”参数必须是函数类型。收到对象的实例

时间:2020-06-17 09:35:53

标签: node.js

如何解决以下问题?我无法提交表单,因为监听器显然应该是一个函数。我正在使用节点版本14.1.0。

错误:

[Op.between]: ["2018-07-08T14:06:48.000Z", "2019-10-08T22:33:54.000Z"]

相关代码:

 TypeError [ERR_INVALID_ARG_TYPE]: The "listener" argument must be of type function. Received an instance of Object

1 个答案:

答案 0 :(得分:1)

这是我的解决方案,它在选项中添加了 url 并移动了其他一些东西:

 app.post("/", function(req, res) {
    
      const email = req.body.email;
   
      // console.log(emailEntry);
    
      const data = {
        members: [{
          email_address: email,
          status: "subscribed"
        }]
      };
    
      const jsonData = JSON.stringify(data)
    
      const options = {
        url: "https://usX.api.mailchimp.com/3.0/lists/LIST_ID",
        method: "POST",
        headers: {
          Authorization: "auth API_KEY"
        },
        body: jsonData
      }
    
      request(options, function(err, response, body) {
        if (err) {
          res.redirect("tryagain");
        } else {
          if (response.statusCode === 200) {
            res.redirect("success");
          } else {
            res.redirect("tryagain");
          }
        }
      });
    });