Fatima Logofatima
Fundamentals

Quickstart

Get started with fatima in minutes.

Init CLI

Use this if you want to skip directly to using a config file.

Next steps in this page will cover a quickstart with no config file.

pnpm add -D fatima
npm install -D fatima
yarn add -D fatima

Installation

pnpm add -D fatima
npm install -D fatima
yarn add -D fatima

Create a .env file

Create a .env file in the root of your project:

.env
PORT=3000
NODE_ENV=development
TZ=UTC
NEXT_PUBLIC_URL=http://localhost:3000

Generate types

This will produce a env.ts file based on the variables in your .env file, with the correct types.

pnpm fatima generate

Path Alias

Make sure you can import env from anywhere in your project without big relative imports:

tsconfig.json
{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "env": ["./env.ts"]
    }
  }
}
package.json
{
  "imports": {
    "#env": "./env.js"
  }
}
jsconfig.json
{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "#env": ["./env.js"]
    }
  }
}

Add env to your .gitignore

You should gitignore your env and always generate it before building/installing.

gitignore
env.ts
gitignore
env.js

Go on and use it

route.ts
import { env } from "env";
import { Response } from "server";

export async function GET() {
  // Full intellisense 👇
  const port = env.PORT;

  return Response(port);
}