Installation
Install the Gland packages you need, configure TypeScript, and verify the toolchain.
Requirements
Section titled “Requirements”| 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.
Create a project
Section titled “Create a project”-
Scaffold a TypeScript project.
Terminal window mkdir my-app && cd my-apppnpm init -
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/expressTerminal window npm install @glandjs/core @glandjs/common @glandjs/events @glandjs/http @glandjs/expressTerminal window yarn add @glandjs/core @glandjs/common @glandjs/events @glandjs/http @glandjs/express -
Install the toolchain and
reflect-metadata.reflect-metadatais a peer dependency of@glandjs/coreand@glandjs/common:Terminal window pnpm add -D typescript @types/nodepnpm add reflect-metadataTerminal window npm install -D typescript @types/nodenpm install reflect-metadataTerminal window yarn add -D typescript @types/nodeyarn add reflect-metadata -
Configure
tsconfig.json.The three options below are required.
useDefineForClassFieldsmust befalse, 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"]} -
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 reference
Section titled “Package reference”| 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 |
Optional extras
Section titled “Optional extras”Some adapter features load their dependency lazily and will tell you if it is missing.
pnpm add cors # required by app.enableCors()First steps walks through building a working API.