ga-wdi-exercises / project3

[Project, Mongo, Mongoose, Node, Express, React, API] Prompt for 3rd WDI Project using React, Node, Mongo, Express and Mongoose
3 stars 4 forks source link

deployment issue with env.js #66

Closed joe-gz closed 8 years ago

joe-gz commented 8 years ago

Hi, I'm working on deploying right now, and I think I've gone through all the steps, but I'm getting an error due to our hidden env.js file i believe:

2015-12-09T14:09:32.235404+00:00 app[web.1]: module.js:340
2015-12-09T14:09:32.235410+00:00 app[web.1]:
2015-12-09T14:09:32.235408+00:00 app[web.1]:     throw err;
2015-12-09T14:09:32.235411+00:00 app[web.1]: Error: Cannot find module './env'

I think that is coming straight from the index.js file, as we have:

var env = require("./env")

app.get ("/incidents", function(req, res) {
  console.log("Call API?");
  var url = "https://api.wmata.com/StationPrediction.svc/json/GetPrediction/All?api_key=" + env.api_key
  request(url, function(error, response, body) {
    console.log(url)
    var incidents = JSON.parse(body)
    res.json(incidents);
  });
});

where heroku is not understand my require("./env") at the top there. I've been searching for a few hours, but I can't find any documentation on an error like this. any thoughts? Thanks!

joe-gz commented 8 years ago

I should note that we are also getting the below error right before the issue above:

Wed, 09 Dec 2015 14:09:32 GMT express-session deprecated undefined resave option; provide resave option at index.js:29:9

I thought that was due to the env.js issue, but i think it might be separate?

RobertAKARobin commented 8 years ago

Take a look at how environment variables are handled here:

https://github.com/ga-dc/super-simple-twitter-app/pull/2

joe-gz commented 8 years ago

So I've set the api_key we have as a variable in heroku already, but don't I still need the env.js file for local work?

RobertAKARobin commented 8 years ago

¿Por que no los dos?

if(app.settings.env == "development"){
  var env = require("./env.js");
}else{
  var env = process.env;
}

That's kind-of a hacky way of handrolling it. You also might look into Figaro for Node.

RobertAKARobin commented 8 years ago

I'ma close this, but please open a new one if necessary!

joe-gz commented 8 years ago

thanks robin! I'll keep you posted