Astro

Encrypt a .env file in Astro with the Dotenvx Node.js SDK, commit it safely, and load its secrets at runtime.

1. Install

Get the Dotenvx Node.js SDK.
$ npm install @dotenvx/dotenvx

2. Encrypt

Encrypt your .env file.

$ npx dotenvx encrypt

3. Inject

Preface Astro scripts with dotenvx run -- and read your env values in Astro.
{
  "scripts": {
    "dev": "dotenvx run -- astro dev",
    "build": "dotenvx run -- astro build",
    "preview": "dotenvx run -- astro preview"
  }
}
export async function GET() {
  return new Response(
    JSON.stringify({
      HELLO: process.env.HELLO,
    }),
    {
      status: 200,
      headers: {
        "Content-Type": "application/json",
      },
    }
  );
}