Search code examples
node.jsibm-cloud

Why do I get Can't get the application_id from VCAP_APPLICATION - local nodeJS server


I created a Bluemix nodeJS app with 'Mobile Client Access' service. The app runs perfectly in Bluemix, however it fails to load when I try to run it local after downloading the code to my laptop. Looks like it needs access to some env variable which is only available in Bluemix not in my local environment. Do I have to create some sort of env file to run it locally? Appreciate your help.

Code causing the error:

var ImfBackendStrategy = require('passport-imf-token-validation').ImfBackendStrategy;
var imf = require('imf-oauth-user-sdk');
passport.use(new ImfBackendStrategy());

Here is the error:

[ERROR] Can't get the application_id from VCAP_APPLICATION, please check if the application running on bluemix.
/Users/xxx/git/DigitalAgent/node_modules/passport-imf-token-validation/lib/imf-backend-strategy.js:31
    throw new TypeError(msg);
          ^
TypeError: Can't get the application_id from VCAP_APPLICATION, please check if the application running on bluemix.
at new Strategy (/Users/xxx/git/DigitalAgent/node_modules/passport-imf-token-validation/lib/imf-backend-strategy.js:31:9)
at Object.<anonymous> (/Users/xxx/git/DigitalAgent/app.js:14:14)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3

Solution

  • You have to set environment variables on your local machine. You can see the variable environment on Bluemix clicking on "Environment Variables" on the left menu in your dashboard console.