2

I'm trying to call a Heroku environment variable in a Node/Express app.

I set the env variable in Heroku using

heroku config:set GITHUB_TOKEN=<my github api token without quotation marks>

It is set correctly (I checked by running heroku config)

gitUserSearchController.js:

githubUserSearch.controller('GitUserSearchController', ['$resource', function($resource) {
  var self = this;

  var searchResource = $resource('https://api.github.com/search/users/');
  var githubToken=process.env.GITHUB_TOKEN;

  self.doSearch = function() {
    self.searchResult = searchResource.get(
      { q: self.searchTerm, access_token: githubToken }
    );
  };
}]);

I get a console error readout of "Reference error: process is not defined" from line 5.

1
  • Are you sure it's not an angular client-side app? It looks that way. Commented Sep 11, 2015 at 11:32

1 Answer 1

2

You can't see local environment variables from the client side of a web app. This is desired behavior, of course, because otherwise you'd have just shared your github token with the world!

process.env.GITHUB_TOKEN will work within node.js, but it won't work in the user's browser (that looks like an Angular controller to be run in the browser, correct?)

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

1 Comment

Long time ago, but yes it was an Angular controller.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.