gpt4 book ai didi

javascript - 导出 NodeJS 模块的问题

转载 作者:行者123 更新时间:2023-12-02 16:18:21 25 4
gpt4 key购买 nike

我有这个目录结构:

  • 应用程序/router.js
  • app/oauth2-home-client/oauth2-client.js

来源:

app/oauth2-home-client/oauth2-client.js

    //SOME CODE

exports.Bearer = {

authenticate : passport.authenticate('bearer', { session : false }),

initialize : passport.initialize()

// session : passport.session()
};

app/router.js

var oauth2 = require('./oauth2-home-client/oauth2-client');

console.log(JSON.stringify(oauth2.Bearer));

//SOME CODE

当我打印 oauth2.Bearer(以及 oauth2)内容时,我得到 {}。我做错了什么?

谢谢。

最佳答案

您的代码:

exports.Bearer = {
authenticate : passport.authenticate('bearer', { session : false }),
initialize : passport.initialize()
// session : passport.session()
};

将导致:

exports.Bearer = {
authenticate :undefined,
initialize : undefined
};

因为 passport.authenticatepassport.initialize 都返回 undefined

并且具有值未定义JSON.stringify省略。 .

[...]If undefined, a function, or a symbol is encountered during conversion it is either omitted (when it is found in an object) or censored to null (when it is found in an array).[...]

关于javascript - 导出 NodeJS 模块的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29377519/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com