#process.env.TRIGGER_ENV exists?
1 messages · Page 1 of 1 (latest)
Where are you wanting to know?
You can get the environment from the task ctx.
https://trigger.dev/docs/context
import { task } from "@trigger.dev/sdk/v3";
export const parentTask = task({
id: "parent-task",
run: async (payload: { message: string }, { ctx }) => {
if (ctx.environment.type === "DEVELOPMENT") {
return;
}
},
});
Failing that, something like:
proces.env.POD_NAME && process.env.POD_NAME.startsWith("task-run-")
Thanks @amber sorrel - it looks good to use inside the trigger task codes.
In Node, we usually check production environment utilising env variables and I wish to learn if Trigger.dev has.
e.g. we have a shared function such as isProd() function which is used in our node server and trigger.dev instance.
Are you self-hosting?
No - we use trigger.dev server
Do you mean the "Production" Trigger.dev environment? So it's different from "Staging"?
We don't have an environment variables for this I don't think, though @dire remnant can confirm that.
We do pass in context like @amber sorrel suggested above.
But obviously it's not a global like process is
I mean we have process.env.NODE_ENV
NODE_ENV probably won't identify that it's trigger specifically
NODE_ENV isn't set to staging though is it? Do you need to be able to tell staging?
Oh I see
Is there any way to detect if it is specifically triggerdev instance? In Vercel, they have NODE_ENV but their preview (aka staging) also returns production so we cannot detect if it is preview or production
You can just use TRIGGER_PROJECT_ID for this
That'll be defined if you are running inside a deployed trigger task
Aha - sounds good. Thanks!
In trigger.dev staging, NODE_ENV is not available?
Yea it is
but it's "production"
we don't have a TRIGGER_ENV although that would be fairly easy to add
NODE_ENV should really only ever be "development" or "production"
Can you create an issue for this?
And what exactly you are trying to do
You could add an environment variable yourself for this BTW
Just don't prefix it with TRIGGER_
I see. Thanks for the details. In our case, we want to have a single function to detect if instance is in production env
export function isProd() {
return (
process.env.VERCEL_ENV === 'production' ||
(process.env.TRIGGER_PROJECT_ID && process.env.NODE_ENV === 'production') //
);
}
In the second condition, how can I detect if this is actual trigger.dev's production?
That won't do it
Just create your own env var in the environment variables page in the dashboard
call it YOUMIN_ENV and have it be "staging" in staging and "production" in prod
Oh I did not think of it. It should be good
export function isProd() {
return (
process.env.VERCEL_ENV === 'production' ||
process.env.TRIGGER_ENV === 'production'
);
}
I can add TRIGGER_ENV into my env variables.
I wouldn't prefix it with TRIGGER_
YOUMIN_TRIGGER_ENV
MY_TRIGGER_ENV
something like that
I see. I guess TRIGGER_ is reserved for system
I feel TRIGGER_ENV from system would be helpful so people can detect environment without adding their own manually
Agreed, it would be great if you could create a GitHub issue requesting this 🙏 https://github.com/triggerdotdev/trigger.dev/issues
Is your feature request related to a problem? Please describe. We frequently check runtime environment (e.g. production, staging) but there is no default environment variable from trigger.dev runti...
Thanks 😍