Apify Discord Mirror

Updated 5 months ago

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

At a glance
The community member is trying to access an environment variable defined in the actor.json file during local development, but is having trouble. They have set a secret proxy_password via the Apify CLI, and are attempting to access it through process.env.PROXY_PASSWORD. However, the community member notes that the CLI documentation suggests environment variables defined in actor.json are only available when the actor is deployed to the Apify cloud, and not during local development. The community member is asking for the recommended approach to achieve this in local development while also playing nicely with deployment.
Useful resources
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