Using packages on their own
Most Plinth packages are ordinary libraries. They do not need Plinth's HTTP layer or container, so you can use them in Express, Fastify, Hono or NestJS.
Standalone (no other Plinth packages)
support, contracts, concurrency, process, notifications, view, vite, vite-plugin
Need only @plinthjs/support
cache, redis, storage, encryption, events, queue, mail, rate-limiter, scheduling, localization, logging, authorization, feature-flags, oauth-server, broadcasting, websockets, search, inspector, monitor, http-client
Need one more standalone package
busandqueue-supervisorneedqueue.oauth-clientneedshttp-client.api-tokensneedscontracts.databaseandormneedconsole.
Tied to Plinth's runtime
core, http, session, auth, accounts, validation, cluster and repl use Plinth's container and router. Using them means running Plinth's HTTP layer.
Example: NestJS providers
Register a package as a Nest provider and inject it as usual:
ts
import { Global, Module } from '@nestjs/common'
import { arrayCache } from '@plinthjs/cache'
import { Encrypter } from '@plinthjs/encryption'
export const CACHE = Symbol('CACHE')
export const ENCRYPTER = Symbol('ENCRYPTER')
@Global()
@Module({
providers: [
{ provide: CACHE, useFactory: () => arrayCache() },
{ provide: ENCRYPTER, useFactory: () => new Encrypter(process.env.APP_KEY!) },
],
exports: [CACHE, ENCRYPTER],
})
export class PlinthModule {}Example: the ORM in NestJS
The ORM reads and writes through @plinthjs/database. Bind the connection once at startup:
ts
import { Schema, sqliteConnection } from '@plinthjs/database'
import { Model } from '@plinthjs/orm'
const db = sqliteConnection({ filename: 'app.db' })
Model.connection = db // Model.where(...), create(), save(), query().with(...), load()
await new Schema(db).create('users', (t) => {
t.increments('id')
t.string('name')
t.timestamps()
})