#process.env.TRIGGER_ENV exists?

1 messages · Page 1 of 1 (latest)

tough sand
#

Hi this env var process.env.TRIGGER_ENV is good to use? I want to detect Trigger.dev instance's environment. I cannot find documentation

export function isProdServer() {
  return (
    process.env.VERCEL_ENV === 'production' ||
    process.env.TRIGGER_ENV === 'production'
  );
}
amber sorrel
#

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;
    }
  },
});
Trigger.dev

Get the context of a task run.

#

Failing that, something like:

proces.env.POD_NAME && process.env.POD_NAME.startsWith("task-run-")
tough sand
#

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.

tame coyote
#

Are you self-hosting?

tough sand
#

No - we use trigger.dev server

tame coyote
#

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

dire remnant
#

I mean we have process.env.NODE_ENV

amber sorrel
#

NODE_ENV probably won't identify that it's trigger specifically

tame coyote
#

NODE_ENV isn't set to staging though is it? Do you need to be able to tell staging?

dire remnant
#

Oh I see

tough sand
dire remnant
#

You can just use TRIGGER_PROJECT_ID for this

#

That'll be defined if you are running inside a deployed trigger task

tough sand
#

Aha - sounds good. Thanks!

tough sand
dire remnant
#

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_

tough sand
#

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?

dire remnant
#

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

tough sand
#

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.

dire remnant
#

I wouldn't prefix it with TRIGGER_

#

YOUMIN_TRIGGER_ENV

#

MY_TRIGGER_ENV

#

something like that

tough sand
#

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

tame coyote
tough sand
tame coyote