10 months ago
My environment variables (GSC_CLIENT_EMAIL, GSC_PRIVATE_KEY, GSC_PROJECT_ID) are not being passed to my Node.js backend. They are set in the Railway dashboard, but always show up as empty in the app. Local tests with the same credentials work perfectly.
I have run a test script to google to see if it is detecting access to properties, it returned with positive results showing all our domains.
We are creating a GSC Monthly Performance app inside our dashboard and this is the only thing keeping us back, we have tested the code everything is 100% correct but for some reason here it is not passing variables at all just returns empty
info: [GSC] ENV GSC_CLIENT_EMAIL:
info: [GSC] ENV GSC_PRIVATE_KEY length:
info: [GSC] ENV GSC_PRIVATE_KEY start:
info: [GSC] ENV GSC_PRIVATE_KEY end:
info: [GSC] ENV GSC_PROJECT_ID:
info: [GSC] Using separate environment variables
Every other related variable to google services is working correctly except this one.
5 Replies
10 months ago
Hey there! We've found the following might help you get unblocked faster:
- 🧵 Node.js Service Failing to Deploy with SIGTERM Error (Health Check Timeout)
- 🧵 Server cant read read env variables i set
- 🧵 Persistent Network Connection Failure
- 🧵 Node.js project throwing sissing environment variables error
If you find the answer from one of these, please let us know by solving the thread!
10 months ago
This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.
Status changed to Open brody • 10 months ago
10 months ago
Can you please provide a screenshot of the service's variables tab, like this:
Furthermore, you can check these things:
a. Correct naming of variables in the server file & railway service
b. Variables have been added to the right environment (production, staging)
c. Private Key Formatting: In the Railway dashboard, input the private key exactly as it is and make sure line breaks are preserved. If you paste a multi-line key into a web form and it gets stripped or line breaks are lost, Node.js may see it as an empty or garbled value.
Are you able to see those variables when consoling them in the code?
Attachments
clashing
Can you please provide a screenshot of the service's variables tab, like this:  Furthermore, you can check these things: a. Correct naming of variables in the server file & railway service b. Variables have been added to the right environment (production, staging) c. **Private Key Formatting:** In the Railway dashboard, input the private key _exactly as it is_ and make sure line breaks are preserved. If you paste a multi-line key into a web form and it gets stripped or line breaks are lost, Node.js may see it as an empty or garbled value. Are you able to see those variables when consoling them in the code?
10 months ago
Both server file & Railway use the same name of variables
All screenshots attached below.
And like mentioned above in production deploy logs do not pick up any data for the variables
info: [GSC] ENV GSC_CLIENT_EMAIL:
info: [GSC] ENV GSC_PRIVATE_KEY length:
info: [GSC] ENV GSC_PRIVATE_KEY start:
info: [GSC] ENV GSC_PRIVATE_KEY end:
info: [GSC] ENV GSC_PROJECT_ID:
And I've created a simple test script to see if the firebase email has permissions for GSC and if it can pull the data from the websites which i got a positive result for it is returning all domains with user permissions set to Full
Private key is formatted in one line which I have checked multiple times.
I have firstly tried just using the GOOGLE_APPLICATION_CREDENTIALS_JSON variable for GSC cause for every other aspect of the dashboard that uses these credentials are working, but GSC did not, after that I have tried this step with setting 3 seperate variables and adjusting the code to those variables, but for some odd reason it just does not want to pull the info given to it.
error: [GSC] Error fetching GSC sites:
error: Error fetching GSC sites: No key or keyFile set. {"stack":"Error: No key or keyFile set.\n at GoogleToken. (/usr/src/app/node_modules/gtoken/build/cjs/src/index.cjs:299:17)\n at Generator. (/usr/src/app/node_modules/gtoken/build/cjs/src/index.cjs:36:1660)\n at Generator.next (/usr/src/app/node_modules/gtoken/build/cjs/src/index.cjs:37:362)\n at asyncGeneratorStep (/usr/src/app/node_modules/gtoken/build/cjs/src/index.cjs:38:70)\n at _next (/usr/src/app/node_modules/gtoken/build/cjs/src/index.cjs:39:163)\n at /usr/src/app/node_modules/gtoken/build/cjs/src/index.cjs:39:299\n at new Promise ()\n at GoogleToken. (/usr/src/app/node_modules/gtoken/build/cjs/src/index.cjs:39:90)\n at GoogleToken._getTokenAsyncInner2 (/usr/src/app/node_modules/gtoken/build/cjs/src/index.cjs:319:31)\n at GoogleToken._getTokenAsyncInner (/usr/src/app/node_modules/gtoken/build/cjs/src/index.cjs:281:31)"}
I've created a log for the variable test itself and it returns to:
GSC_CLIENT_EMAIL: undefined
GSC_PRIVATE_KEY length: undefined
GSC_PRIVATE_KEY start: undefined
GSC_PRIVATE_KEY end: undefined
GSC_PROJECT_ID: undefined
Missing one or more required GSC environment variables.
Attachments
d3dic1
Both server file & Railway use the same name of variables **All screenshots attached below.** And like mentioned above in production deploy logs do not pick up any data for the variables info: \[GSC\] ENV GSC\_CLIENT\_EMAIL: info: \[GSC\] ENV GSC\_PRIVATE\_KEY length: info: \[GSC\] ENV GSC\_PRIVATE\_KEY start: info: \[GSC\] ENV GSC\_PRIVATE\_KEY end: info: \[GSC\] ENV GSC\_PROJECT\_ID: And I've created a simple test script to see if the firebase email has permissions for GSC and if it can pull the data from the websites which i got a positive result for it is returning all domains with user permissions set to Full Private key is formatted in one line which I have checked multiple times. I have firstly tried just using the GOOGLE\_APPLICATION\_CREDENTIALS\_JSON variable for GSC cause for every other aspect of the dashboard that uses these credentials are working, but GSC did not, after that I have tried this step with setting 3 seperate variables and adjusting the code to those variables, but for some odd reason it just does not want to pull the info given to it. error: \[GSC\] Error fetching GSC sites: error: Error fetching GSC sites: No key or keyFile set. {"stack":"Error: No key or keyFile set.\\n at GoogleToken.<anonymous> (/usr/src/app/node\_modules/gtoken/build/cjs/src/index.cjs:299:17)\\n at Generator.<anonymous> (/usr/src/app/node\_modules/gtoken/build/cjs/src/index.cjs:36:1660)\\n at [Generator.next](http://Generator.next) (/usr/src/app/node\_modules/gtoken/build/cjs/src/index.cjs:37:362)\\n at asyncGeneratorStep (/usr/src/app/node\_modules/gtoken/build/cjs/src/index.cjs:38:70)\\n at _next (/usr/src/app/node_modules/gtoken/build/cjs/src/index.cjs:39:163)\\n at /usr/src/app/node\_modules/gtoken/build/cjs/src/index.cjs:39:299\\n at new Promise (<anonymous>)\\n at GoogleToken.<anonymous> (/usr/src/app/node\_modules/gtoken/build/cjs/src/index.cjs:39:90)\\n at GoogleToken.\_getTokenAsyncInner2 (/usr/src/app/node\_modules/gtoken/build/cjs/src/index.cjs:319:31)\\n at GoogleToken.\_getTokenAsyncInner (/usr/src/app/node\_modules/gtoken/build/cjs/src/index.cjs:281:31)"} I've created a log for the variable test itself and it returns to: GSC\_CLIENT\_EMAIL: undefined GSC\_PRIVATE\_KEY length: undefined GSC\_PRIVATE\_KEY start: undefined GSC\_PRIVATE\_KEY end: undefined GSC\_PROJECT\_ID: undefined Missing one or more required GSC environment variables.
10 months ago
- Have you restarted the service/re-deployed it after changing the variables, so that the new variables could be fetched?
- Can you please share the code snippet in which you did this: "setting 3 separate variables and adjusting the code to those variables", along with the screenshot which shows the initial lines of your server configuration.
- Do add a "healthcheckup" endpoint in your server to check whether the server is being loaded properly! Refer to this post: https://station.railway.com/questions/node-js-service-failing-to-deploy-with-s-dc58e402#mk2w
- Also, for just an instance, do not use env variables, and hardcode the same into your code to see whether then the code is working or not (that will confirm that Railway is having some issue with env variables)
10 months ago
Any update, d3dic1