Use inquirer without commander #1053
-
Is it possible to use only the inquirer part for nest-commander in a classic REST API ? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
I'm not entirely sure what sense this makes. Inquirer is for asking questions and getting responses through the terminal. How would that work in your REST API? |
Beta Was this translation helpful? Give feedback.
-
It works with import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import * as inquirer from 'inquirer';
import { questions } from './pizza';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.listen(3000);
while (true) {
//@ts-ignore
const answer = await inquirer.prompt(questions);
console.log(answer);
// call a nest service with answer
}
}
bootstrap(); [Nest] 22940 - 02/10/2023 17:14:24 LOG [NestFactory] Starting Nest application...
[Nest] 22940 - 02/10/2023 17:14:24 LOG [InstanceLoader] AppModule dependencies initialized +12ms
? Is this for delivery? (y/N) [Nest] 22940 - 02/10/2023 17:14:24 LOG [RoutesResolver] AppController {/}: +50ms
[Nest] 22940 - 02/10/2023 17:14:24 LOG [RouterExplorer] Mapped {/, GET} route +5ms
[Nest] 22940 - 02/10/2023 17:14:24 LOG [NestApplication] Nest application successfully started +3ms
? Is this for delivery? Yes
? What's your phone number? 0123546879
? What size do you need? Large
? How many do you need? 2
? What about the toppings? Pepperoni and cheese
? You also get a free 2L beverage 7up
? Any comments on your purchase experience? Nope, all good!
{
toBeDelivered: true,
phone: '0123546879',
size: 'large',
quantity: 2,
toppings: 'PepperoniCheese',
beverage: '7up',
comments: 'Nope, all good!'
}
? Is this for delivery? (y/N) |
Beta Was this translation helpful? Give feedback.
So, technically, you can use
imports: [CommandRunnerModule.forRoot()]
to create the module that provides and exports theInquirerService
. It also provides theCommandRunnerService
, but that should be okay, it'll just look for@Command()
classes, find nothing, and set nothing up from them.