SJaka
SJaka

Reputation: 830

Why Node.js CLI app hangs after completion till break with Ctrl-C?

I've a simple Node.js command line program that uses commander and inquirer for taking command line inputs. It then connects to MongoDB Atlas to carryout its operations in index.js file, and after connection to DB is closed, it just hangs there till process is broken with Ctrl-C. Even if I call an empty function with no connection to DB, it still does the same. Here is the code:

#!/usr/bin/env node

const program = require('commander');
const { prompt } = require('inquirer');
const {addProduct, findProduct, findOrder} = require('./index');

const questions = [
    {
        type: 'input',
        name: 'id',
        message: 'Product ID'
    }
];

program
    .version('1.0.0')
    .description('Test program to create records');

program
    .command('search')
    .alias('s')
    .description('Find a product by ProductID')
    .action(() => {
        prompt(questions). then((answers) => {
            findProduct(answers)
        })
    }); 

program.parse(process.argv);   

What am I doing wrong here?

Edit: I've tried both program.prase() and program.parseAsync() with the same result.

Upvotes: 0

Views: 383

Answers (0)

Related Questions