Not for nodejs, but for GO (GOLANG), save each field value as a separate key in environment variables, and then you will need to do something like this, create a structure, convert to json ( replacing each \\n with \n in private_key ), enter the parameter. WithCredentialsJSON :
type credentialsData struct { Type string 'json:"type"' ProjectId string 'json:"project_id"' PrivateKeyId string 'json:"private_key_id"' PrivateKey string 'json:"private_key"' ClientEmail string 'json:"client_email"' ClientId string 'json:"client_id"' AuthUri string 'json:"auth_uri"' TokenUri string 'json:"token_uri"' AuthProviderX509CertUrl string 'json:"auth_provider_x509_cert_url"' ClientX509CertUrl string 'json:"client_x509_cert_url"' } func firebase_init() *firebase.App { backSlashFix := strings.Replace(os.Getenv("FIREBASE_PRIVATE_KEY"), "\\n", "\n", -1) json_cred := &credentialsData{ Type: os.Getenv("FIREBASE_ACCOUNT_TYPE"), ProjectId: os.Getenv("FIREBASE_PROJECT_ID"), PrivateKeyId: os.Getenv("FIREBASE_PRIVATE_KEY_ID"), PrivateKey: backSlashFix, ClientEmail: os.Getenv("FIREBASE_CLIENT_EMAIL"), ClientId: os.Getenv("FIREBASE_CLIENT_ID"), AuthUri: os.Getenv("FIREBASE_AUTH_URI"), TokenUri: os.Getenv("FIREBASE_TOKEN_URI"), AuthProviderX509CertUrl: os.Getenv("FIREBASE_AUTH_PROVIDER_X509_CERT_URL"), ClientX509CertUrl: os.Getenv("FIREBASE_CLIENT_X509_CERT_URL"), } bytes, e := json.Marshal(json_cred) if e != nil { panic(fmt.Errorf("Could not create json from credentials struct", e)) } opt := option.WithCredentialsJSON([]byte(string(bytes))) app, err := firebase.NewApp(context.Background(), &firebase.Config{ProjectID: "<your project id>"}, opt) if err != nil { panic(fmt.Errorf("error initializing app: %v", err)) } return app }
source share