Skip to content

Read .env file #207

Answered by ellmetha
notramo asked this question in Q&A
Mar 12, 2024 · 1 comments · 4 replies
Discussion options

You must be logged in to vote

Hey! Marten does not prescribe a specific method for utilizing environment variables. Developers can choose their preferred approach, whether it's using a .env file or any other method, to define environment-specific values. This decision is left to the discretion of developers.

If you want to use .env files in your project, I would recommend using the cr-dotenv shard and simply making sure to initialize settings by reading environment variables using ENV. For example:

require "dotenv"

Dotenv.load?

Marten.configure do |config|
  config.secret_key = ENV.fetch("MARTEN_SECRET_KEY") { raise "Missing MARTEN_SECRET_KEY env variable" }
end

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@notramo
Comment options

@ellmetha
Comment options

@notramo
Comment options

@ellmetha
Comment options

Answer selected by ellmetha
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants