Better-TS-Stack

Configuration

Environment variables, package.json, and TypeScript configuration

Configuration Overview

Better-TS-Stack generates projects with sensible defaults, but you'll need to configure environment variables and can customize various settings.


Environment Variables

Backend (.env)

The CLI writes these variables to .env and .env.example based on selected modules:

# Base (always generated)
NODE_ENV=development
PORT=3000

# + PostgreSQL (Prisma or Drizzle)
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/postgres?schema=public"

# + MongoDB (Mongoose)
MONGODB_URI="mongodb://localhost:27017/myapp"

# + JWT Auth (Express)
JWT_SECRET=please-change-me
JWT_EXPIRES_IN=1h

Full-stack / Next.js (.env)

# Base (always generated)
NODE_ENV=development
PORT=3000

# + Better Auth (requires database)
BETTER_AUTH_SECRET=please-change-me-to-a-random-string
BETTER_AUTH_URL=http://localhost:3000

Environment-Specific Files

You can create separate files for different environments:

  • .env.development - Development-specific
  • .env.production - Production-specific
  • .env.test - Testing environment

Never commit .env files to version control! Use .env.example as a template.


TypeScript Configuration

Backend tsconfig.json

{
  "compilerOptions": {
    "target": "ES2020",
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "types": ["node"],
    "lib": ["ES2020"],
    "outDir": "./dist",
    "rootDir": "./src",
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "resolveJsonModule": true,
    "moduleResolution": "node",
    "declaration": true,
    "declarationMap": true,
    "sourceMap": true
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules", "dist", "tests"]
}

Frontend tsconfig.json

Next.js generates this automatically with modern settings:

{
  "compilerOptions": {
    "target": "ES2017",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "bundler",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "plugins": [
      {
        "name": "next"
      }
    ],
    "paths": {
      "@/*": ["./*"]
    }
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
  "exclude": ["node_modules"]
}

Package.json Scripts

Backend (Express) scripts

These are generated by the Express base module:

{
  "scripts": {
    "dev": "tsx watch src/index.ts",
    "build": "tsc",
    "start": "node dist/index.js",
    "lint": "eslint src",
    "lint:fix": "eslint src --fix",
    "format": "prettier --write \"src/**/*.ts\"",
    "type:check": "tsc --noEmit"
  }
}

With bun, dev becomes bun --watch src/index.ts.

Prisma module adds: prisma:generate, prisma:migrate, prisma:studio

Docker module adds: docker:build, docker:up, docker:down, docker:logs

Full-stack (Next.js) scripts

These are generated by the Next.js base module:

{
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "eslint"
  }
}

Prisma module adds: prisma:generate, prisma:migrate, prisma:studio

Drizzle module adds: db:generate, db:migrate, db:studio

Docker module adds: docker:build, docker:up, docker:down, docker:logs


ESLint Configuration

Backend .eslintrc.json

{
  "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "ecmaVersion": 2020,
    "sourceType": "module"
  },
  "plugins": ["@typescript-eslint"],
  "rules": {
    "@typescript-eslint/explicit-function-return-type": "off",
    "@typescript-eslint/no-explicit-any": "warn",
    "@typescript-eslint/no-unused-vars": [
      "error",
      { "argsIgnorePattern": "^_" }
    ]
  },
  "env": {
    "node": true,
    "es2020": true
  }
}

Prettier Configuration

.prettierrc

{
  "semi": true,
  "singleQuote": false,
  "tabWidth": 2,
  "trailingComma": "es5",
  "printWidth": 80,
  "arrowParens": "always"
}

Docker Configuration

Multi-Stage Dockerfile

See full Dockerfile in Docker Module.

docker-compose.yml

The generated file is minimal - only the app service is defined:

services:
  your-project:
    build: .
    ports:
      - "3000:3000"
    env_file:
      - .env
    environment:
      - NODE_ENV=production
    restart: unless-stopped

Database services are not generated automatically. Add them manually if needed. See the Docker module docs for an example.


Prisma Configuration

schema.prisma

generator client {
  provider = "prisma-client"
  output = "../src/generated/prisma"
  moduleFormat = "cjs"
}

datasource db {
  provider = "postgresql"
}

model User {
  id        String   @id @default(uuid())
  email     String   @unique
  name      String?
  password  String
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  @@map("users")
}

In Next.js projects, the datasource URL is loaded via prisma.config.ts. If Better Auth is enabled, the generated Prisma schema includes Better Auth tables (user, session, account, verification).

prisma.config.ts (Next.js)

import "dotenv/config";
import { defineConfig, env } from "prisma/config";

export default defineConfig({
  schema: "prisma/schema.prisma",
  migrations: {
    path: "prisma/migrations",
  },
  datasource: {
    url: env("DATABASE_URL"),
  },
});

prisma/migrations

Run migrations:

# Create migration
npx prisma migrate dev --name add_user_table

# Apply migrations
npx prisma migrate deploy

# Reset database (careful!)
npx prisma migrate reset

Next.js Configuration

next.config.ts

The generated file is intentionally minimal:

import type { NextConfig } from "next";

const nextConfig: NextConfig = {};

export default nextConfig;

Add options as your project grows. Refer to the Next.js configuration docs for available options.


Custom Configuration

Adding Custom Scripts

Edit package.json:

{
  "scripts": {
    "db:seed": "tsx prisma/seed.ts",
    "db:reset": "prisma migrate reset --force",
    "docker:build": "docker build -t myapp .",
    "docker:run": "docker run -p 3000:3000 myapp"
  }
}

Custom TypeScript Paths

Add to tsconfig.json:

{
  "compilerOptions": {
    "paths": {
      "@/*": ["./src/*"],
      "@/components/*": ["./src/components/*"],
      "@/lib/*": ["./src/lib/*"]
    }
  }
}

All configuration files are editable after generation. Customize them to fit your project's specific needs.

On this page