Skip to content

Plugins Overview ​

πŸ”Œ Plugins are modular extensions that add reusable features to your Nevr application.

Why Plugins? ​

The Problem: Features That Every App Needs ​

FeatureWithout PluginsWith Plugins
AuthenticationWrite 500+ lines of auth codeauth({ emailAndPassword: { enabled: true } })
TimestampsAdd createdAt/updatedAt to every entity manuallyOne-line plugin for all entities
Rate limitingBuild custom middlewarerateLimit({ max: 100 })
LoggingImplement hooks everywherePlugin auto-hooks all requests

🟒 Beginner Tip: Think of plugins as "drop-in features". You install them, configure them, and they just workβ€”without writing the underlying code.

What Plugins Can Add ​

CapabilityDescriptionExample
EntitiesNew database tables/modelsUser, Session, Account
EndpointsCustom API operations/auth/sign-in, /auth/sign-out
InterceptorsRequest/response processingAuthentication checks, logging
Entity HooksCRUD lifecycle callbacksbeforeCreate, afterDelete
ServicesInjectable utilitiesEmail service, Payment processor

Using Plugins ​

Plugins are passed to the nevr configuration:

typescript
import { nevr } from "nevr"
import { auth } from "nevr/plugins/auth"
import { timestamps } from "nevr/plugins/timestamps"

const api = nevr({
  entities: [user, post],
  driver: prisma(db),
  
  plugins: [
    // Official plugin with options
    auth({
      emailAndPassword: { enabled: true },
      socialProviders: {
        google: { clientId: "...", clientSecret: "..." },
        github: { clientId: "...", clientSecret: "..." },
      },
    }),
    
    // Official simple plugin
    timestamps(),
    
    // Your custom plugin
    myCustomPlugin({ apiKey: "..." }),
  ]
})

🟑 Intermediate Tip: Plugins are applied in order. If plugin B depends on plugin A, make sure A comes first in the array.


Official Plugin Ecosystem ​

PluginPackageDescriptionStatus
Authnevr/plugins/authComplete authentication systemβœ… Ready
Timestampsnevr/plugins/timestampsAuto createdAt/updatedAtβœ… Ready

Creating Your Own Plugins ​

Quick Example 🟒 ​

typescript
import { createPlugin, endpoint } from "nevr"

const helloWorld = createPlugin({
  id: "hello",
  name: "Hello World",
  version: "1.0.0",
  
  lifecycle: {
    onInit: () => console.log("πŸ‘‹ Hello from Plugin!")
  },
  
  endpoints: {
    hello: endpoint("/hello", {
      method: "GET",
      handler: async () => ({ message: "Hello World!" }),
    }),
  },
})

Configurable Plugin 🟑 ​

typescript
interface Options {
  greeting: string
  shout?: boolean
}

const greetPlugin = createPlugin<Options>({
  id: "greet",
  name: "Greeting Plugin",
  version: "1.0.0",
  
  defaults: { shout: false },
  
  factory: (options) => ({
    endpoints: {
      greet: endpoint("/greet", {
        method: "GET",
        handler: async () => {
          const msg = options.greeting
          return { message: options.shout ? msg.toUpperCase() : msg }
        },
      }),
    },
  }),
})

// Usage
nevr({ plugins: [greetPlugin({ greeting: "Welcome!" })] })

See Creating Plugins for the full guide.


Plugin API at a Glance ​

FunctionUse CaseLevel
createPlugin()Most plugins🟒 Recommended
createPlugin() with factoryConfigurable plugins

Next Steps ​

Released under the MIT License.