Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nestjs-console

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nestjs-console

A NestJS module that provide a cli

  • 0.1.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
30K
increased by7.26%
Maintainers
1
Weekly downloads
 
Created
Source

nestjs-console

NestJS Console is a module that provide a cli. A ready to use service class for your module that exposes the required methods to register commands and sub commands using the npm package commander

Install

npm install nestjs-console
# or unig yarn
yarn install nestjs-console

Prepare the cli endpoint

Create a file next to main.ts named console.ts
Import your app module or any module you want to be loaded. Usually this is your main nestjs module.

// console.ts
import { bootstrap } from 'nestjs-console';
import { MyAppModule } from './my.application.module';

bootstrap(MyAppModule, { logger: false }).catch(e => console.log('Error', e));

Usage

An example of nestjs module that import the ConsoleModule

// module.ts
import { Module } from '@nestjs/common';
import { ConsoleModule } from 'nestjs-console';
import { MyService } from './service';

@Module({
    imports: [
        ConsoleModule
    ],
    providers: [MyService]
    exports: [MyService]
})
export class MyModule {}

You can now inject the ConsoleService inside any nestjs providers, controllers...

// service.ts
import { Injectable } from '@nestjs/common';
import { ConsoleService } from 'nestjs-console';

@Injectable()
export class MyService {
    constructor(private readonly consoleService: ConsoleService) {
        this.consoleService
            .getCli()
            .command('mycommand')
            .options('-a, --all', 'an exemple of options')
            .action(this.myCommand.bind(this));
    }

    myCommand(options) {
        //See Ora npm package for details about spinner
        const spin = this.consoleService.createSpinner();
        spin.start();
        // DO SOME WORK
        console.log(options.all);
        spin.stop();
    }
}

Add scripts in your package.json (Only if you want to use them)

{
    "scripts": {
        "console:dev": "ts-node -r tsconfig-paths/register src/console.ts",
        "console": "node lib/console.js"
    }
}

Usage from cli (we suppose your app was built in the lib forlder)

# direct call
node lib/console.js --help

# using npm
npm run console -- --help

# using yarn
yarn run console --help

# during dev you can call the console using ts-node
yarn run console:dev --help

Documentation

A typedoc is generated and available on github https://pop-code.github.io/nestjs-console

Keywords

FAQs

Package last updated on 06 Mar 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc