CA
harsh-harlequin

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.
Environment variables | Apify Documentation
There are two options how you can set up environment variables for actors.
1 Reply
harsh-harlequin
harsh-harlequinOP2y ago
// actor.json
{
// ...rest of actor.json
"environmentVariables": {
"PROXY_PASSWORD": "@proxy_password"
},
}
// 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?

Did you find this page helpful?