Long Environment Variable with line breaks (\n)

I’m using Gridsome and included a Firestore plugin to source data from.

When using the Netlify environment variables my private key doesn’t work out because it includes many line breaks (/n in the .json file).

Is there a way to avoid this issue in the Netlify UI?

hi there,

I’m not 100% sure about this, but it could also be related to this limitation:

is this applicable to your situation?

I don’t believe so…

I ended up added quotes around the entire variable in Netlify and then doing a JSON.parse(process.env.private_key)

1 Like

Bit late to the party, but the way I’ve escaped in the past is shown here: [Support Guide] Using an SSH key via environment variable during build

Environment variables with embedded carriage returns are pretty hard for the shell, so a pattern like this is preferred even outside of the netlify build shell :slight_smile:

Thanks @fool :wink:

The parsing of the string is working fine for me at the moment so I think I’ll just keep it like that unless I run into any issues and refer back to your solution.

1 Like

Thanks all. In JS, doing string substitution also seemed to work:

process.env.PRIVATE_KEY.replace(/\\n/gm, "\n")
2 Likes