提问者:小点点

在node.js中exports.local用于什么


exports.local节点js示例代码

我在node js应用程序中使用passport-local-Mogoose,我遇到了用于passport身份验证的exports.local。 我不明白它的功能。 请检查上面的图像


共1个答案

匿名用户

在node.js中使用CommonJS(CJS)格式,并使用require和module.exports定义依赖项和模块。 国家预防机制生态系统就是建立在这种形式之上的。 在您的示例中,exports.local创建一个新模块,并将其导出以供程序的其他地方使用。

示例user.js

const getName = () => {
   return 'Jim';
};

exports.getName = getName;

index.js

const user = require('./user');
console.log(`User: ${user.getName()}`);

输出量

用户:Jim