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 🙏

© 2026 – Pkg Stats / Ryan Hefner

nestjs-console-oclif

v1.0.5

Published

A NestJS module that integrate oclif to build nice cli

Downloads

26

Readme

NestJS + Oclif

pipeline status

nestjs-console-oclif is a NestJS module that provides a CLI with Oclif.

Getting started

Generate your NestJS application

The architecture is based on NestJS architecture. So you can generate your application with nestcli : https://docs.nestjs.com/first-steps

Install from NPM

npm install @oclif/command @oclif/config @oclif/errors @oclif/parser nestjs-console-oclif
# or unig yarn
yarn add @oclif/command @oclif/config @oclif/errors @oclif/parser nestjs-console-oclif

:warning: Don't forget to specify Oclif options in package.json :

{
  // ...
  "scripts": {
    "build": "nest build && oclif-dev manifest"
  },
  // ...
  "devDependencies": {
    // ...
    "@oclif/dev-cli": "^1.22.2",
    // ...
  },
  "bin": {
    "myCli": "./dist/main.js"
  },
  // ...
  "oclif": {
    "commands": "./dist/commands",
    "bin": "myCli",
    "plugins": [
      "@oclif/plugin-help"
    ]
  }
  // ...
}

Override NestJS bootstrap

Replace in file src/main.ts with AppModule as your main NestJS module:

#!/usr/bin/env node

import { bootstrap } from 'nestjs-console-oclif';
import { AppModule } from './app.module';

bootstrap({
  nestModule: AppModule
});

Options :

  • nestModule : The class of the NestJS module
  • singleCommand: The class of the single command
  • enableShutdownHooks: true if you want enable shutdown hooks on the NestJS app. See NestJS lifecycle events

Import OclifModule

Import OclifModule in your main NestJS module (in file src/app.module.ts).

import { Module } from '@nestjs/common';
import { OclifModule } from 'nestjs-console-oclif';

@Module({
  imports: [OclifModule.forRoot()],
  providers: [...],
})
export class AppModule {
}

Define your commands

Multi commands

You define your command in src/commands/myCommand.ts like oclif.

But :

  • Extends your command from BaseCommand
  • You don't need to implement the run function.
import { BaseCommand } from 'nestjs-console-oclif';
import { flags } from '@oclif/command';

export class MyCommand extends BaseCommand {
  static description = 'description of this example command';

  static flags: = {
    myFlag: flags.string({
      char: 'f',
      description: 'My flag',
    })
  };

  static args = [
    {name: 'myArg'}
  ];
}

Single command

Define your command in src/commands/myCommand.ts, but specify the command in bootstrap function :

#!/usr/bin/env node

import { bootstrap } from 'nestjs-console-oclif';
import { AppModule } from './app.module';
import { MyCommand } from './commands/myCommand';

bootstrap({
  nestModule: AppModule,
  singleCommand: MyCommand
});

Register your commands entrypoints

Define the entrypoint of the command defined in MyCommand.

:warning: The entrypoint does not take arguments.

import { Injectable } from '@nestjs/common';
import { OclifCommand } from 'nestjs-console-oclif';

@Injectable()
export class AppService {

  @OclifCommand('myCommand')
  async run(): Promise<void> {
    // Do something
  }
}

Read Args and flags

Load your parameters from NestJS context with the decorators OclifArgs and OclifFlags :

import { OclifFlags, OclifCommand, OclifArgs } from 'nestjs-console-oclif';
import { Injectable } from '@nestjs/common';

@Injectable()
export class AppService {
  constructor(
        @OclifFlags('myFlag') protected myFlag: string,
        @OclifArgs('myArg') protected myArg: string) {
  }

  @OclifCommand('myCommand')
  async run(): Promise<void> {
    console.log(`my flag : ${this.myFlag}`);
    console.log(`my arg : ${this.myArg}`);
  }
}