Unable to set RSA private key as config var : <p>I'm trying to deploy an Express app to Heroku. The trouble I'm having is that Heroku or something along the way is screwing up the format of the RSA private key string. I have the following in my <code>.env</code> which works locally and is kept out of git:</p>

<pre><code>TYPE=
PROJECT_ID=
PRIVATE_KEY_ID=
PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n"
CLIENT_EMAIL=
CLIENT_ID=
AUTH_URI=
TOKEN_URI=
AUTH_CERT_URL=
CLIENT_CERT_URL=
</code></pre>

<p>I initially used <a href="https://github.com/xavdid/heroku-config" rel="noreferrer">https://github.com/xavdid/heroku-config</a> to set the above vars instead of doing it by hand through the dashboard on Heroku, but that private key failed.</p>

<p>Then I tried setting that value manually by copy/pasting (without double quotes) through the Heroku Dashboard, still failed.</p>

<p>Finally I set the value via <code>heroku config:set</code>, but still fails to parse it when the app starts up.</p>

<p>I even tried replacing <code>\n</code> with <code>'\n'</code> as someone did <a href="https://github.com/auth0/node-jsonwebtoken/issues/191" rel="noreferrer">here</a> and using quotes with <code>heroku config:set PRIVATE_KEY=""</code>, but still doesn't work.</p>

<p>So my question is, is Heroku doing something funky with the long string value? Or am I missing something. The above values are called/used as shown below:</p>

<pre><code>const { credential } = require('firebase-admin')

exports.serviceAccount = {
  type: process.env.TYPE,
  project_id: process.env.PROJECT_ID,
  private_key_id: process.env.PRIVATE_KEY_ID,
  private_key: process.env.PRIVATE_KEY,
  client_email: process.env.CLIENT_EMAIL,
  client_id: process.env.CLIENT_ID,
  auth_uri: process.env.AUTH_URI,
  token_uri: process.env.TOKEN_URI,
  auth_provider_x509_cert_url: process.env.AUTH_CERT_URL,
  client_x509_cert_url: process.env.CLIENT_CERT_URL
}

exports.credential = credential.cert(exports.serviceAccount)

exports.databaseURL = process.env.DATABASE_URL

exports.adminConfig = {
  credential: exports.credential,
  databaseURL: exports.databaseURL
}
</code></pre>

<p>And logs from Heroku:</p>

<pre><code>2017-06-05T01:50:13.761150+00:00 app[web.1]: &gt; NODE_ENV=production node ./server/server.prod.js
2017-06-05T01:50:14.231853+00:00 app[web.1]: /app/node_modules/firebase-admin/lib/auth/credential.js:129
2017-06-05T01:50:14.231876+00:00 app[web.1]:             throw new error_1.FirebaseAppError(error_1.AppErrorCodes.INVALID_CREDENTIAL, 'Failed to parse private key: ' + error);
2017-06-05T01:50:14.231877+00:00 app[web.1]:             ^
2017-06-05T01:50:14.231878+00:00 app[web.1]:
2017-06-05T01:50:14.231878+00:00 app[web.1]: Error: Failed to parse private key: Error: Invalid PEM formatted message.
2017-06-05T01:50:14.231883+00:00 app[web.1]:     at FirebaseAppError.FirebaseError [as constructor] (/app/node_modules/firebase-admin/lib/utils/error.js:39:28)
2017-06-05T01:50:14.231884+00:00 app[web.1]:     at new FirebaseAppError (/app/node_modules/firebase-admin/lib/utils/error.js:84:23)
2017-06-05T01:50:14.231885+00:00 app[web.1]:     at new Certificate (/app/node_modules/firebase-admin/lib/auth/credential.js:129:19)
2017-06-05T01:50:14.231886+00:00 app[web.1]:     at new CertCredential (/app/node_modules/firebase-admin/lib/auth/credential.js:195:33)
2017-06-05T01:50:14.231887+00:00 app[web.1]:     at Object.cert (/app/node_modules/firebase-admin/lib/firebase-namespace.js:189:58)
2017-06-05T01:50:14.231887+00:00 app[web.1]:     at Object.&lt;anonymous&gt; (/app/server/firebase/index.js:16:33)
2017-06-05T01:50:14.231888+00:00 app[web.1]:     at Module._compile (module.js:569:30)
2017-06-05T01:50:14.231888+00:00 app[web.1]:     at Object.Module._extensions..js (module.js:580:10)
2017-06-05T01:50:14.231889+00:00 app[web.1]:     at Module.load (module.js:503:32)
2017-06-05T01:50:14.231889+00:00 app[web.1]:     at tryModuleLoad (module.js:466:12)
</code></pre>
