npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

nuxt-nust

v1.0.14

Published

Nestjs-like api controllers for your Nuxt backend

Readme

Nust Module for Nuxt

npm version npm downloads License Nuxt

Nust is a nuxt module that allows NestJS like backend structure in nuxt, Standardizing your backend with CRUD structure, powering nuxt backend with features like:

  • 🎮  Controllers
  • 🖌️  Decorators
  • 🛎️  Injectable providers/services
  • 🪄️  Parameter extraction
  • ✅️  Body/DTO Validation (using class-validator)
  • 🔄️  Transformers (using class-transformer)
  • 🔒️  Guards
  • 📖️  OpenAPI documentation support, Nestjs like Api documentation decorators for better Swagger and Scalar support

🏀  Online playground

📖  Documentation

Usage

  1. Install the module to your Nuxt application:
npm i nuxt-nust
  1. Add nuxt-nust to list of modules in your nuxt.config.ts file, along with nust configuration:
// nuxt.config.ts
export default defineNuxtConfig({
  modules: ['nuxt-nust'],
  nust: {
    controllersFile: 'server/nust/index.ts', // Path to controllers export file in your project relative to root folder
    debug: false, // Enable to show the routes added by your controllers in the logs
  }
})
  1. Create a file in your project to export all controllers that sits under the path specified in the previous step, for example: server/nust/index.ts
// server/nust/index.ts
import { type NustControllers } from '#nust'

export default {
  // Here you'll be adding your controller classes
  // Example:
  // post: PostController
} satisfies NustControllers
  1. Update the tsconfig.json files by adding the following lines:
{
  "extends": "../.nuxt/tsconfig.server.json",
  "compilerOptions": {
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "strictPropertyInitialization": false
  }
}
  1. That's it! You can now use Nust Module in your Nuxt app ✨

Example of adding a controller, lets call this one CatController

1.Create a controller file under the nust directory, server/nust/cat/Cat.controller.ts

import { Controller, type H3Event } from '#nust'

@Controller('cat')
export class CatController {

  @Get('')
  findAll(event: H3Event) {
    return `this action returns all cats`
  }
  
}
  1. Add controller to server/nust/index.ts file
// server/nust/index.ts
import {type NustControllers} from '#nust'
import { CatController } from "./cat/Cat.controller";

export default {
  cat: CatController
} satisfies NustControllers
  1. Restart nuxt service
  2. Now the endpoint /api/cat is available

Concept

Turn your server structure from this:

From this:

server/
├── api/
│   ├── cat/
│   │   ├── index.get.ts   //Find all
│   │   ├── index.post.ts  //Create
│   │   ├── [id].get.ts    //Find one
│   │   ├── [id].patch.ts  //Update
│   │   └── [id].delete.ts //delete
│   └── dog/
│       ├── index.get.ts   //Find all
│       ├── index.post.ts  //Create
│       ├── [id].get.ts    //Find one
│       ├── [id].patch.ts  //Update
│       └── [id].delete.ts //delete
└── utils/
    ├── catUtilss.ts
    └── dogUtils.ts

To this: (Just and example, structure can be however you like)

server/
├── nust/
│   ├── cat/
│   │   ├── dto/               // For example, you can add your CRUD dto's here
│   │   │   ├── CreateCat.dto.ts
│   │   │   └── UpdateCat.dto.ts
│   │   ├── entity/            // For example, you can add your resource relevent types here
│   │   ├── cat.controller.ts  // Has all the CRUD methods
│   │   └── cat.service.ts     // cat service provider, can be used to hold all logic, allowing it to be injected to any controller and reuse the logic
│   └── dog/
│   │   ├── dog.controller.ts  // Has all the CRUD methods
│   │   └── dog.service.ts     // dog service provider
└── index.ts                   // controllersFile, a file that exports an object of all controllers

If you've worked with other backend focused frameworks you'd find this structure familiar, where the logic for a CRUD resource all sits under one folder/module, helps keep the backend code organised and its logic reusable.

Resource controllers?

Your event handler changes from this:

//index.get.ts
export default defineEventHandler((event)=>{
  //...
  return //
})
//index.post.ts
export default defineEventHandler((event)=>{
  //...
  return //
})
//[id].get.ts
export default defineEventHandler((event)=>{
  //...
  return //
})
//[id].post.ts
export default defineEventHandler((event)=>{
  //...
  return //
})
//[id].delete.ts
export default defineEventHandler((event)=>{
  //...
  return //
})

To this:

import {Controller, Get, Post, Delete, Body, Param} from '#nust'

@Controller('cat') // Prefix can be defind here or you can just add it to each method
export class CatController {
  // Get all
  @Get('')
  findAll() {
    //...
  }

  // POST Create
  @Post('')
  create(event: H3Event, @Body(CreateCatDto) dto: CreateCatDto) {
    //...
  }

  // Get one
  @Get(':id')
  findOne(event: H3Event, @Param('id') id: string): CatEntity {
    //..
  }

  @Patch(':id')
  update(
    event: H3Event,
    @Param('id') id: string,
    @Body(UpdateCatDto) dto: UpdateCatDto,
  ) {
    //...
  }

  @Delete(':id')
  delete(event: H3Event, @Param('id') id: string) {
    //...
  }
  
  @Any('get-random-cat')
  otherNoneStandardCRUDmethod(event: H3Event) {
    //...
  }
}

Documentation

https://sweetscript.github.io/nuxt-nust/guide/setup.html

Contribution

Contributions are welcome 🙏

# Install dependencies
npm install

# Generate type stubs
npm run dev:prepare

# Develop with the playground
npm run dev

# Build the playground
npm run dev:build

# Run ESLint
npm run lint

# Run Vitest
npm run test
npm run test:watch

# Release new version
npm run release