Multiline strings in .env files

John Reilly March 9, 2024
Source
I love using .env files to configure my applications. They're a great way to keep configuration in one place and to keep it out of the codebase. They're also a great way to keep secrets out of the codebase. But what if you need to use a multiline string in a .env file? How do you do that? You just do it: That's right, you just use a newline character. It's that simple. Oddly, searching for that on the internet didn't yield the answer I was looking for. So I'm writing it down here for posterity. With your .env file in place, you can then consume it in your application using a package like dotenv. Or if you'd like to use a bash script to consume the .env file, you can do it like this:

Discussion in the ATmosphere

Loading comments...