How do i use env variables in lifecycle files?

env() global is not available and there is no env to be used from a exported method. How do I access it?

This topic has been created from a Discord post (1219756258702397560) to give it more visibility.
It will be on Read-Only mode here.
Join the conversation on Discord

You need to import the env function in order to access it

const { env } = require("@strapi/utils");

module.exports = {
  beforeCreate(event) {
    const myEnv = env("MY_ENV_VAR");
    console.log("MY_ENV_VAR: ", myEnv);
    console.log("before create fired with data: ", event.params.data);
  },

};

This should work for you

Great, thanks :slightly_smiling_face:

<@166823910858424320> you are welcom