Skip to content

noConvexProcessEnv (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"nursery": {
"noConvexProcessEnv": "error"
}
}
}
}

Disallow process.env in Convex functions.

Convex can give you a typed env object for your environment variables. To get it, declare the variables in convex/convex.config.ts, and then import env from _generated/server. With env, TypeScript reports misspelled variable names, tells you which variables are optional, and a deploy fails early when a required variable is missing. With process.env, every variable has the type string | undefined, and misspelled names are only found when the code runs.

This rule only checks files inside the convex folder of a package, which is the folder next to its package.json. Other code, such as frontend code, keeps using process.env. Files inside the convex/_generated folder are not checked.

The fix replaces process.env with env, and imports env from _generated/server when the file doesn’t import it yet. The fix is unsafe, because the code only compiles once the variable is declared in convex/convex.config.ts.

package.json
{
"dependencies": { "convex": "*" }
}
convex/giphy.ts
const apiKey = process.env.GIPHY_KEY;
/convex/giphy.ts:1:16 lint/nursery/noConvexProcessEnv  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ Don't use process.env in Convex functions.

> 1 │ const apiKey = process.env.GIPHY_KEY;
│ ^^^^^^^^^^^
2 │

ℹ Variables read from process.env have no types, so misspelled or missing variables are only found when the code runs.

ℹ Declare the environment variables in convex/convex.config.ts, and read them from the env object exported by _generated/server.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

ℹ Unsafe fix: Use the env object from _generated/server instead.

1 │ - const·apiKey·=·process.env.GIPHY_KEY;
1 │ + import·{·env·}·from·"./_generated/server";
2 │ + const·apiKey·=·env.GIPHY_KEY;
2 3 │

convex/keys.ts
const { GIPHY_KEY } = process.env;
/convex/keys.ts:1:23 lint/nursery/noConvexProcessEnv  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ Don't use process.env in Convex functions.

> 1 │ const { GIPHY_KEY } = process.env;
│ ^^^^^^^^^^^
2 │

ℹ Variables read from process.env have no types, so misspelled or missing variables are only found when the code runs.

ℹ Declare the environment variables in convex/convex.config.ts, and read them from the env object exported by _generated/server.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

ℹ Unsafe fix: Use the env object from _generated/server instead.

1 │ - const·{·GIPHY_KEY·}·=·process.env;
1 │ + import·{·env·}·from·"./_generated/server";
2 │ + const·{·GIPHY_KEY·}·=·env;
2 3 │

package.json
{
"dependencies": { "convex": "*" }
}
convex/giphy.ts
import { env } from "./_generated/server";
const apiKey = env.GIPHY_KEY;

The variable is declared in convex/convex.config.ts:

convex/convex.config.ts
import { defineApp } from "convex/server";
import { v } from "convex/values";
const app = defineApp({
env: { GIPHY_KEY: v.string() },
});
export default app;
  • If you want to disallow process.env in every file, see noProcessEnv.