olawalejuwonm
olawalejuwonm

Reputation: 1535

What is exports.local used for in node.js

Exports.local Node js sample code

I am using passport-local-mongoose in my node js Application and I come across exports.local for passport authentication. I couldn't understand it function. Please check the image above

Upvotes: 3

Views: 612

Answers (2)

Mitch
Mitch

Reputation: 596

The CommonJS (CJS) format is used in Node.js and uses require and module.exports to define dependencies and modules. The npm ecosystem is built upon this format. In your case exports.local creates a new module and export it for the use elsewhere.

Example user.js

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

exports.getName = getName;

index.js

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

Output

User: Jim

Upvotes: 0

Karim
Karim

Reputation: 218

In your case here there is nothing special about local keyword, it is just the name of the variable that is used to export the passport local authentication strategy configuration, so you can call it in other files using require, so here in your example, you have this logic written in authenticate.js, so to use it in any other file you will have to call it using the following:

const { local } =  require('./authenticate'); // identify the right path to authenticate.js
enter code here

Upvotes: 1

Related Questions