0

I have this directory structure:

  • app/router.js
  • app/oauth2-home-client/oauth2-client.js

And the sources:

app/oauth2-home-client/oauth2-client.js

    //SOME CODE

    exports.Bearer = {

            authenticate : passport.authenticate('bearer', { session : false }),

            initialize : passport.initialize()

            // session : passport.session()
    };

app/router.js

var oauth2 = require('./oauth2-home-client/oauth2-client');

console.log(JSON.stringify(oauth2.Bearer));

//SOME CODE

When I print oauth2.Bearer (and oauth2, too) content, I get {}. What am I doing wrong?

Thanks.

5
  • Where is your router.js located? Commented Mar 31, 2015 at 20:03
  • In app/, same directory that oauth2-home-client folder. I have edited my question for clarity. Commented Mar 31, 2015 at 20:07
  • Try this var oauth2 = require('oauth2-home-client/oauth2-client'); instead of var oauth2 = require('./oauth2-home-client/oauth2-client'); Commented Mar 31, 2015 at 20:11
  • Also try putting quotes around authenticate and initialize in JSON. Commented Mar 31, 2015 at 20:12
  • You should show what you want to do with oauth2.Bearer currently it is just possible to tell why you get this result, but not how to solve it. Do you want to do oauth2.Bearer.authenticate() which then should call passport.authenticate('bearer', { session : false })? Commented Mar 31, 2015 at 20:34

2 Answers 2

3

Your code:

exports.Bearer = {
  authenticate : passport.authenticate('bearer', { session : false }),
  initialize : passport.initialize()
  // session : passport.session()
};

Will result in:

exports.Bearer = {
  authenticate :undefined,
  initialize : undefined
};

because both passport.authenticate and passport.initialize return undefined.

And the keys having the value undefined are omitted by JSON.stringify.

[...]If undefined, a function, or a symbol is encountered during conversion it is either omitted (when it is found in an object) or censored to null (when it is found in an array).[...]

Sign up to request clarification or add additional context in comments.

Comments

-1

Its value may point to the module instantiation. Have you try this?

module.exports = {...};

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.