unni_ramachandran
unni_ramachandran

Reputation: 73

Unable to access environment variables in google cloud (node js express app)

I am a beginner trying to learn web development. I have built small node js app and deployed in heroku. I am trying to do the same in GCP and learn the platform.

Code used is @ https://github.com/unnikrishnan-r/firstgcpdeployment

The issue that I am facing is Unable to access env variables in the app

My index.js

exports.envVar = (req, res) => {
    // Sends 'bar' as response
    console.log("bbbccc");
    console.log(process.env.JAWSDB_URL);
    res.status(200).send(process.env.JAWSDB_URL);
    return process.env.JAWSDB_URL;
  };

.env.yaml is JAWSDB_URL: testtest456

I then used below to deploy the function to gcloud gcloud functions deploy envVar --env-vars-file .env.yaml --runtime nodejs8 --trigger-http;

Deployment was successful and was tested using console and https://us-central1-howtodeployingcp.cloudfunctions.net/envVar

During deploy this happened img

Can some one help me here?

Upvotes: 1

Views: 874

Answers (1)

jcragun
jcragun

Reputation: 2198

It seems this line is problematic:

var dbUrl = envVar.envVar();

You're calling the function without passing in req, res as it's expecting. Perhaps you forgot to comment out this line.

Upvotes: 1

Related Questions