Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/408.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript exports.local在node.js中用于什么_Javascript_Node.js_Export_Passport.js_Node Modules - Fatal编程技术网

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

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('.

我在我的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('./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