Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
361 views
in Technique[技术] by (71.8m points)

javascript - Escaping issue with firebase privateKey as a Heroku config variable

I'm trying to create an Heroku node task that reads data from Firebase and console.log it.

My node script (located inside the /bin directory) is:

require('dotenv').config({ silent: true });

var firebase = require('firebase');
firebase.initializeApp({
  serviceAccount: {
    projectId: process.env.fb_projectId,
    clientEmail: process.env.fb_clientEmail,
    privateKey: process.env.fb_privateKey
  },
  databaseURL: process.env.fb_databaseURL
})

console.log(process.env.fb_privateKey);

firebase.database().ref('tasks').once('value', function(snapshot) {
  console.log(snapshot.val());
  process.exit();
})

All env variables are correct, except fb_privateKey, since it contains characters.

Both my local .env file and Heroku environment variables contains a key named fb_privateKey and a value as a string with characters - surrounded with ".

fb_privateKey="-----BEGIN PRIVATE KEY-----
MY-PRIVATE-KEY
-----END PRIVATE KEY-----
"

When I run the script locally, it logs me the private key with new lines + the tasks that were returned from Firebase. However, when I run it on Heroku, (heroku run myScript) is logs me private key with characters (as a single line) and fails to read the data from Firebase (probably due to a bad private key). Any ideas?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...