I’m using firebase in my project and I want to store its serviceAccountKey.json file in .env file like this
SERVICE_ACCOUNT_KEY={
"type": "service_account",
"project_id": "abc-123",
"private_key_id": "123",
"private_key": "-----BEGIN PRIVATE KEY-----n**some string**n-----END PRIVATE KEY-----n",
"client_email": "firebase-adminsdk-whatever.gserviceaccount.com",
"client_id": "123",
"auth_uri": "https://something",
"token_uri": "https://something",
"auth_provider_x509_cert_url": "https://something",
"client_x509_cert_url": "https://something.com"
}
And I’m reading this in my firebase-config file like this
const admin = require("firebase-admin");
const serviceAccount = process.env.SERVICE_ACCOUNT_KEY;
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: process.env.DATABASE_URL,
});
It says
Failed to parse service account json file: Error: ENOENT: no such file or directory
And then I tried to parse this file like this
const serviceAccount = JSON.parse(process.env.SERVICE_ACCOUNT_KEY)
And now it’s saying
Failed to parse private key: Error: Invalid PEM formatted message.
Please help me storing this json file in .env file