What does “.Strategy” do in Node or Passport?
What does ".Strategy" do here? Is it Node? Is it Passport?
var LocalStrategy = require('passport-local').Strategy;
Everything up to '.Strategy' part I understand. I just want to know what '.Strategy' does. I have checked the documentation on passport-local module on npm. I have also checked Passport's documentation, and it is just used in code snippets. No explanation is provided.
I am working with the MEAN stack and we are using Passport to authenticate users.
node.js passport.js mean-stack
|
show 2 more comments
What does ".Strategy" do here? Is it Node? Is it Passport?
var LocalStrategy = require('passport-local').Strategy;
Everything up to '.Strategy' part I understand. I just want to know what '.Strategy' does. I have checked the documentation on passport-local module on npm. I have also checked Passport's documentation, and it is just used in code snippets. No explanation is provided.
I am working with the MEAN stack and we are using Passport to authenticate users.
node.js passport.js mean-stack
Did you look at npmjs.com/package/passport-local? Search for "passport strategy"? I seem to be finding a fair bit of documentation.
– jonrsharpe
Nov 10 at 18:08
Yeah, that's the first place I looked. It doesn't exactly tell me what ".Strategy" does though. Everything leading up to the ".Strategy" part I understand.
– UhHuhOkSure
Nov 10 at 18:13
What do you mean what it does? You can see the implementation, it's open source. Or look at the abstract version: github.com/jaredhanson/passport-strategy
– jonrsharpe
Nov 10 at 18:16
I didn't know to look in the local strategy source code because there wasn't anything in the documentation about it. As far as I could tell, it could have been a Node thing or a Passport thing.
– UhHuhOkSure
Nov 10 at 18:31
But you can see where it's coming from when you require it, what other information would you need to find it? You can see in the index file it comes from strategy.js, which seems logical.
– jonrsharpe
Nov 10 at 18:32
|
show 2 more comments
What does ".Strategy" do here? Is it Node? Is it Passport?
var LocalStrategy = require('passport-local').Strategy;
Everything up to '.Strategy' part I understand. I just want to know what '.Strategy' does. I have checked the documentation on passport-local module on npm. I have also checked Passport's documentation, and it is just used in code snippets. No explanation is provided.
I am working with the MEAN stack and we are using Passport to authenticate users.
node.js passport.js mean-stack
What does ".Strategy" do here? Is it Node? Is it Passport?
var LocalStrategy = require('passport-local').Strategy;
Everything up to '.Strategy' part I understand. I just want to know what '.Strategy' does. I have checked the documentation on passport-local module on npm. I have also checked Passport's documentation, and it is just used in code snippets. No explanation is provided.
I am working with the MEAN stack and we are using Passport to authenticate users.
node.js passport.js mean-stack
node.js passport.js mean-stack
edited Nov 10 at 18:16
asked Nov 10 at 18:06
UhHuhOkSure
1225
1225
Did you look at npmjs.com/package/passport-local? Search for "passport strategy"? I seem to be finding a fair bit of documentation.
– jonrsharpe
Nov 10 at 18:08
Yeah, that's the first place I looked. It doesn't exactly tell me what ".Strategy" does though. Everything leading up to the ".Strategy" part I understand.
– UhHuhOkSure
Nov 10 at 18:13
What do you mean what it does? You can see the implementation, it's open source. Or look at the abstract version: github.com/jaredhanson/passport-strategy
– jonrsharpe
Nov 10 at 18:16
I didn't know to look in the local strategy source code because there wasn't anything in the documentation about it. As far as I could tell, it could have been a Node thing or a Passport thing.
– UhHuhOkSure
Nov 10 at 18:31
But you can see where it's coming from when you require it, what other information would you need to find it? You can see in the index file it comes from strategy.js, which seems logical.
– jonrsharpe
Nov 10 at 18:32
|
show 2 more comments
Did you look at npmjs.com/package/passport-local? Search for "passport strategy"? I seem to be finding a fair bit of documentation.
– jonrsharpe
Nov 10 at 18:08
Yeah, that's the first place I looked. It doesn't exactly tell me what ".Strategy" does though. Everything leading up to the ".Strategy" part I understand.
– UhHuhOkSure
Nov 10 at 18:13
What do you mean what it does? You can see the implementation, it's open source. Or look at the abstract version: github.com/jaredhanson/passport-strategy
– jonrsharpe
Nov 10 at 18:16
I didn't know to look in the local strategy source code because there wasn't anything in the documentation about it. As far as I could tell, it could have been a Node thing or a Passport thing.
– UhHuhOkSure
Nov 10 at 18:31
But you can see where it's coming from when you require it, what other information would you need to find it? You can see in the index file it comes from strategy.js, which seems logical.
– jonrsharpe
Nov 10 at 18:32
Did you look at npmjs.com/package/passport-local? Search for "passport strategy"? I seem to be finding a fair bit of documentation.
– jonrsharpe
Nov 10 at 18:08
Did you look at npmjs.com/package/passport-local? Search for "passport strategy"? I seem to be finding a fair bit of documentation.
– jonrsharpe
Nov 10 at 18:08
Yeah, that's the first place I looked. It doesn't exactly tell me what ".Strategy" does though. Everything leading up to the ".Strategy" part I understand.
– UhHuhOkSure
Nov 10 at 18:13
Yeah, that's the first place I looked. It doesn't exactly tell me what ".Strategy" does though. Everything leading up to the ".Strategy" part I understand.
– UhHuhOkSure
Nov 10 at 18:13
What do you mean what it does? You can see the implementation, it's open source. Or look at the abstract version: github.com/jaredhanson/passport-strategy
– jonrsharpe
Nov 10 at 18:16
What do you mean what it does? You can see the implementation, it's open source. Or look at the abstract version: github.com/jaredhanson/passport-strategy
– jonrsharpe
Nov 10 at 18:16
I didn't know to look in the local strategy source code because there wasn't anything in the documentation about it. As far as I could tell, it could have been a Node thing or a Passport thing.
– UhHuhOkSure
Nov 10 at 18:31
I didn't know to look in the local strategy source code because there wasn't anything in the documentation about it. As far as I could tell, it could have been a Node thing or a Passport thing.
– UhHuhOkSure
Nov 10 at 18:31
But you can see where it's coming from when you require it, what other information would you need to find it? You can see in the index file it comes from strategy.js, which seems logical.
– jonrsharpe
Nov 10 at 18:32
But you can see where it's coming from when you require it, what other information would you need to find it? You can see in the index file it comes from strategy.js, which seems logical.
– jonrsharpe
Nov 10 at 18:32
|
show 2 more comments
1 Answer
1
active
oldest
votes
If you look at the sources of passport-local
index.js
you'll see it exports the same thing directly and in exports.Strategy
.
When you do require('passport-local).Strategy
you import the export defined in exports.Strategy
, but it's really the same to do just require('passport-local')
in this case because the same constructor is exported directly from the module.
If you define a module like this:
var Thing = { foo: () => 'bar' };
exports = module.exports = Thing;
exports.Thing = Thing;
you can use it in many ways:
const Thing = require('./module');
console.log(Thing.foo());
works, as does
const Thing = require('./module').Thing;
console.log(Thing.foo());
and with both imports you can actually call also
console.log(Thing.Thing.foo());
If you remove the exports.Thing = Thing;
part of the module, then
const Thing = require('./module').Thing;
does not work anymore.
The exports cause confusion often. You could take a look of Node docs or eg. this answer.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241922%2fwhat-does-strategy-do-in-node-or-passport%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you look at the sources of passport-local
index.js
you'll see it exports the same thing directly and in exports.Strategy
.
When you do require('passport-local).Strategy
you import the export defined in exports.Strategy
, but it's really the same to do just require('passport-local')
in this case because the same constructor is exported directly from the module.
If you define a module like this:
var Thing = { foo: () => 'bar' };
exports = module.exports = Thing;
exports.Thing = Thing;
you can use it in many ways:
const Thing = require('./module');
console.log(Thing.foo());
works, as does
const Thing = require('./module').Thing;
console.log(Thing.foo());
and with both imports you can actually call also
console.log(Thing.Thing.foo());
If you remove the exports.Thing = Thing;
part of the module, then
const Thing = require('./module').Thing;
does not work anymore.
The exports cause confusion often. You could take a look of Node docs or eg. this answer.
add a comment |
If you look at the sources of passport-local
index.js
you'll see it exports the same thing directly and in exports.Strategy
.
When you do require('passport-local).Strategy
you import the export defined in exports.Strategy
, but it's really the same to do just require('passport-local')
in this case because the same constructor is exported directly from the module.
If you define a module like this:
var Thing = { foo: () => 'bar' };
exports = module.exports = Thing;
exports.Thing = Thing;
you can use it in many ways:
const Thing = require('./module');
console.log(Thing.foo());
works, as does
const Thing = require('./module').Thing;
console.log(Thing.foo());
and with both imports you can actually call also
console.log(Thing.Thing.foo());
If you remove the exports.Thing = Thing;
part of the module, then
const Thing = require('./module').Thing;
does not work anymore.
The exports cause confusion often. You could take a look of Node docs or eg. this answer.
add a comment |
If you look at the sources of passport-local
index.js
you'll see it exports the same thing directly and in exports.Strategy
.
When you do require('passport-local).Strategy
you import the export defined in exports.Strategy
, but it's really the same to do just require('passport-local')
in this case because the same constructor is exported directly from the module.
If you define a module like this:
var Thing = { foo: () => 'bar' };
exports = module.exports = Thing;
exports.Thing = Thing;
you can use it in many ways:
const Thing = require('./module');
console.log(Thing.foo());
works, as does
const Thing = require('./module').Thing;
console.log(Thing.foo());
and with both imports you can actually call also
console.log(Thing.Thing.foo());
If you remove the exports.Thing = Thing;
part of the module, then
const Thing = require('./module').Thing;
does not work anymore.
The exports cause confusion often. You could take a look of Node docs or eg. this answer.
If you look at the sources of passport-local
index.js
you'll see it exports the same thing directly and in exports.Strategy
.
When you do require('passport-local).Strategy
you import the export defined in exports.Strategy
, but it's really the same to do just require('passport-local')
in this case because the same constructor is exported directly from the module.
If you define a module like this:
var Thing = { foo: () => 'bar' };
exports = module.exports = Thing;
exports.Thing = Thing;
you can use it in many ways:
const Thing = require('./module');
console.log(Thing.foo());
works, as does
const Thing = require('./module').Thing;
console.log(Thing.foo());
and with both imports you can actually call also
console.log(Thing.Thing.foo());
If you remove the exports.Thing = Thing;
part of the module, then
const Thing = require('./module').Thing;
does not work anymore.
The exports cause confusion often. You could take a look of Node docs or eg. this answer.
answered Dec 5 at 20:35
vesse
3,1311130
3,1311130
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241922%2fwhat-does-strategy-do-in-node-or-passport%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Did you look at npmjs.com/package/passport-local? Search for "passport strategy"? I seem to be finding a fair bit of documentation.
– jonrsharpe
Nov 10 at 18:08
Yeah, that's the first place I looked. It doesn't exactly tell me what ".Strategy" does though. Everything leading up to the ".Strategy" part I understand.
– UhHuhOkSure
Nov 10 at 18:13
What do you mean what it does? You can see the implementation, it's open source. Or look at the abstract version: github.com/jaredhanson/passport-strategy
– jonrsharpe
Nov 10 at 18:16
I didn't know to look in the local strategy source code because there wasn't anything in the documentation about it. As far as I could tell, it could have been a Node thing or a Passport thing.
– UhHuhOkSure
Nov 10 at 18:31
But you can see where it's coming from when you require it, what other information would you need to find it? You can see in the index file it comes from strategy.js, which seems logical.
– jonrsharpe
Nov 10 at 18:32