Skip to content
engineering workbench.by StudyPort Academy
Learning path
Advanced18 min

Environment and secrets

Understand the idea

A key can be present in the process and still must not appear in source or in a log line.

The idea

This runner does not set AI_API_KEY, so the first line reads environment and prints missing. The second line uses a local object only so the run can show a present key without reading a real secret from your shell. The report is the word present and the length. The JSON log repeats that report. It does not print sk-demo. Production code should read process.env.AI_API_KEY at the edge and pass the value into the client that needs it. Do not commit that value. Do not put it in a fixture that ships.

What changes

Where a secret ends up
PlaceSafe?What to store instead
Environment variableYes, on the machine that runs the processThe key
Source fileNoNothing. Read the environment
Log lineNopresent or missing
Response bodyNoAn error that does not echo the header

The command

Report presence, not the key

3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.

The mistake

Check the result

The lines are missing, then present 7, then a JSON log whose key field is present 7. The characters sk-demo are not in the output.

Guided challenge

Report presence, not the key

report currently returns the raw key. Change it so a present key prints present and the length, never the characters.

Report presence, not the key

3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.

EXPECTED RESULT

missing
present 7

Hints 0/2

    Use all hints or make 3 failed checks (0/3).

    Free exploration

    Change this example and run it again. Each run is a new process. Nothing is saved.

    Your variation

    3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.

    Quiz

    A quick check for understanding. Retry as often as you like; your learning path stays open.

    01Where should a provider key live?
    02What may a log line say about the key?

    Ready to call this one understood?

    Mark this lesson complete to earn 200 XP. You can always revisit it.

    Sign in to save progress
    Next lesson