Javascript exports.local在node.js中用于什么
我在我的node js应用程序中使用passport local mongoose,遇到exports.local用于passport身份验证。我无法理解它的功能。请查看上图Node.js中使用CommonJS(CJS)格式,并使用require和module.exports定义依赖项和模块。npm生态系统就是基于这种格式构建的。在您的情况下,Javascript exports.local在node.js中用于什么,javascript,node.js,export,passport.js,node-modules,Javascript,Node.js,Export,Passport.js,Node Modules,我在我的node js应用程序中使用passport local mongoose,遇到exports.local用于passport身份验证。我无法理解它的功能。请查看上图Node.js中使用CommonJS(CJS)格式,并使用require和module.exports定义依赖项和模块。npm生态系统就是基于这种格式构建的。在您的情况下,exports.local创建一个新模块并将其导出以供其他地方使用 范例 user.js index.js const user = require('.
exports.local
创建一个新模块并将其导出以供其他地方使用
范例
user.js
index.js
const user = require('./user');
console.log(`User: ${user.getName()}`);
输出
用户:吉姆
在您的例子中,
local
关键字没有什么特别之处,它只是用于导出passport本地身份验证策略配置的变量的名称,因此您可以使用require
在其他文件中调用它,因此在您的示例中,此逻辑是用authenticate.js
编写的,因此,要在任何其他文件中使用它,您必须使用以下命令调用它:
const { local } = require('./authenticate'); // identify the right path to authenticate.js
enter code here
const { local } = require('./authenticate'); // identify the right path to authenticate.js
enter code here