Nodes/ComfyUI-Env-Loader/Env Key Selector
ComfyUI Node

Env Key Selector

Pull one secret from a dropdown, none of it in your workflow JSON

By hubo502·Created 9 months ago·Updated 9 months ago· 0
Env Key Selector
    • value
    key

    ComfyUI workflow files are just JSON, and JSON travels. Every API token you type into a text node rides along in the export, which is exactly how keys end up pasted into shared workflows on comfy.icu and Reddit. Env Key Selector is the calm fix: it reads the .env file in your ComfyUI root, shows you a dropdown of its keys, and outputs the value of whichever one you pick. Your secret stays in .env, not in the workflow.

    It's half of ComfyUI-Env-Loader, a two-node pack by Boris Hu (hubo502). Its sibling, Env Keys, dumps every key onto its own output port at once; this node is the single-value version. If your workflow needs exactly one secret - an API key for a generator node, a model path, a flag - this is the tidier choice, and it self-documents which keys the workflow expects.

    How it works

    The pack locates ComfyUI root by walking up from its own directory until it finds a folder containing custom_nodes, then parses .env next to it - ENV_PATH is always <ComfyUI root>/.env. The parser is a ~30-line stdlib-only affair: no python-dotenv, no requirements.txt, no dependencies. INPUT_TYPES builds the dropdown from the current keys, get_value() re-reads the file and returns the value, and IS_CHANGED returns the file's mtime so a re-run picks up edits without a restart.

    Inputs and outputs that matter

    Only one input, and it's the whole point:

    • key - an enum dropdown of the keys parsed from .env. Pick one.

    And one output:

    • value - a STRING holding the selected key's current value.

    No .env present? The dropdown has a single empty option and value comes back as "". Everything is a string, so "true" is the literal text, not a boolean - fine for feeding into anything that expects the raw text.

    What to wire it into

    value is a plain STRING, so it plugs into any string input: an API-key field on an API-calling node, a text concat, a filename. This is the crowd that actually trips over .env - look at the support threads for API-token generator nodes and you'll find the recurring question "where is the .env file?" It lives at the ComfyUI root, the folder above custom_nodes, and ComfyUI will not create it for you; the first time, you make it yourself.

    The refresh story is the good part

    Because the dropdown options come from INPUT_TYPES - which ComfyUI re-queries when you open the menu - new keys show up without a restart, and mtime-based change detection handles value updates. About the only thing that ever needs a restart here is the initial import. That makes EnvKeySelector the "live" node of the pair; Env Keys is the "all at once" one.

    Install

    Via ComfyUI Manager, "Install via URL" with the repo, or manually:

    cd path/to/ComfyUI/custom_nodes
    git clone https://github.com/hubo502/ComfyUI-Env-Loader.git
    

    Restart ComfyUI and it lands under Utils. No model downloads, no heavy dependencies - the whole pack is two MIT-licensed Python classes. Drop a .env at the ComfyUI root (beside custom_nodes):

    API_KEY=12345
    MODEL_PATH="C:/Models"
    

    # comments, blank lines, and quoted values are all handled.

    Common issues

    • Empty dropdown: .env isn't at the ComfyUI root, or it has no valid KEY=VALUE lines.
    • Value won't update: re-trigger the graph; the mtime-based change detection should re-run the node.
    • Nothing shows after install: restart ComfyUI so the node actually imports and reads the file.

    Reach for this when you care about one or two keys, or when you hand workflows to other people - a dropdown is friendlier than a wall of ports. Many keys, many consumers? Env Keys. One key you actually need? This.

    CategoryUtils

    Inputs (1)

    NameTypeDefaultDescription
    keyCOMBO1 options:

    Outputs (1)

    NameTypeDescription
    valueSTRING