Apify and Crawlee Official Forum

Updated 3 months ago

Using env vars with secret values via `apify secrets:add`, `actor.json`, and default start script

The documentation (https://docs.apify.com/cli/docs/vars) doesn't touch on how you access any environment variables set in actor.json in an actor's source–I'm using the monorepo example repository.
s
6 comments
Plain Text
// actor.json
{
  // ...rest of actor.json
  "environmentVariables": {
    "PROXY_PASSWORD": "@proxy_password"
  },
}
I set my proxy_password secret via apify secrets:add proxy_password ...
I'm attempting to access the env var via process.env.PROXY_PASSWORD, and the start script is node --no-warnings --experimental-specifier-resolution=node --loader ../../module_loader.js src/index.ts
what am I missing here?
the CLI's help for secrets suggests that environment variables defined in actor.json are not available during local development: When the actor is pushed to Apify cloud, the "SECRET_ENV_VAR" and its value is stored as a secret environment variable of the actor.
If that's the case, what is the recommended approach for achieving this in local dev so that it plays nicely with being deployed?
Add a reply
Sign up and join the conversation on Discord