Skip to content

Installation

Install the Gland packages you need, configure TypeScript, and verify the toolchain.

Node.js >= 20.9.0
TypeScript >= 5.0
Package manager pnpm (recommended), npm or Yarn

Gland relies on reflect-metadata for decorator metadata, and on experimentalDecorators plus emitDecoratorMetadata from TypeScript. Both are set up for you below.

  1. Scaffold a TypeScript project.

    Terminal window
    mkdir my-app && cd my-app
    pnpm init
  2. Install the runtime packages.

    For an HTTP application with the Express adapter:

    Terminal window
    pnpm add @glandjs/core @glandjs/common @glandjs/events @glandjs/http @glandjs/express
  3. Install the toolchain and reflect-metadata.

    reflect-metadata is a peer dependency of @glandjs/core and @glandjs/common:

    Terminal window
    pnpm add -D typescript @types/node
    pnpm add reflect-metadata
  4. Configure tsconfig.json.

    The three options below are required. useDefineForClassFields must be false, or decorator metadata is lost.

    tsconfig.json
    {
    "compilerOptions": {
    "target": "ES2022",
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "strict": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "useDefineForClassFields": false,
    "skipLibCheck": true,
    "outDir": "dist"
    },
    "include": ["src"]
    }
  5. Verify the installation.

    src/main.ts
    import 'reflect-metadata'
    import { EventBroker } from '@glandjs/events'
    const broker = new EventBroker({ name: 'smoke-test' })
    broker.on('ping', (payload) => console.log(payload))
    broker.emit('ping', { ok: true })
    Terminal window
    npx tsc && node dist/main.js
    # { ok: true }
Package What it gives you Install it if
@glandjs/core DI container, module bootstrap, lifecycle hooks, Context always
@glandjs/common @Module, @Controller, @Channel, @On, @Inject always
@glandjs/events EventBroker, channels, mesh networking, IOEvent always
@glandjs/http Route decorators, HttpContext, HttpCore, HttpBroker you serve HTTP
@glandjs/express The Express 5 adapter you use Express
@glandjs/emitter Standalone zero-dependency event emitter you want a pub/sub primitive without the framework

Some adapter features load their dependency lazily and will tell you if it is missing.

Terminal window
pnpm add cors # required by app.enableCors()

First steps walks through building a working API.