How to get value from .env file

default discord avatar
quandn
3 months ago
2

I'm querying my documents and need to get server_url from .env file, but I dont how how to get it. Please help me

  • default discord avatar
    donfabrizio
    3 months ago

    If your .env file is at the root of your project, you should be able to get your variables by using process.env.YOUR_VARIABLE_NAME, ex: serverURL: process.env.PAYLOAD_URL



    Does that answer your question?

  • discord user avatar
    denolfe
    Payload Team
    3 months ago

    Like Lou said, should be accessible via

    process.env.MY_VALUE

    . Ensure you're using

    dotenv

    to load them properly.



    import dotenv from 'dotenv'
    
    dotenv.config()
Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.