将var声明为模块

时间:2019-11-29 08:19:07

标签: node.js

我在自己的javascript文件中使用了一个节点模块。我添加了module.export来从其他功能访问它,但这会引起问题。当前看起来像:

var POP3Client = require("mailpop3");
let client;

module.exports = {
    startPop3Abfrage: function(login,password){
        client = new POP3Client('995', 'outlock.office.de', {

            tlserrs: false,
            enabletls: true,
            debug: false

        });
    }
};


client.on("error", function(err) {

    if (err.errno === 111) console.log("Unable to connect to server");
    else console.log("Server error occurred");

    console.log(err);

});

client.on("connect", function() {

    console.log("CONNECT success");
    client.login('xxx', 'xxx');

});

client.on("login", function(status, rawdata) {

    if (status) {

        console.log("LOGIN/PASS success");
        client.list();

    } else {

        console.log("LOGIN/PASS failed");
        client.quit();

    }
});


client的声明似乎是错误的,因为节点报告:

TypeError: Cannot read property 'on' of undefined

我如何声明/定义client以便

on.

会起作用吗?

0 个答案:

没有答案
相关问题