Weird behaviour of the Inquirer package printing multiple times

I am trying to create a cli tool which downloads packages (internally uses npm) and create files. I am using inquirer to ask for user input on what database they’d like to add but the output from inquirer is not what I expected it to be.

This is my code (I have skipped the imports and other boilerplate code):

const questions = [
  {
      type: 'list',
      name: 'option',
      message: 'Choose an option:',
      choices: [
          'MongoDB (mongoose)',
          'Firebase',
          'PostgreSQL',
          'MySQL',
          'Redis'
      ],
  }
];

argv.command({
  command: 'create-node-app',
  describe: 'Creates a basic node project with usual files',
  builder: {
    y: {
      describe: "Use default values to build the package.json",
      demandOption: false
    }
  },
  handler: async (argv) => {
    let packages = [];
    let dependencies = '';
    const execa = util.promisify(exec);

    async function setup(jsonFile) {
      // no libraries are given, add default librariesthen create the file
      if (argv._.length == 1) {
        console.log(chalk.yellow("Note: Predefined libraries will be added to the package.json"));
        
        console.log(chalk.yellow("Please select the database you'd like to connect to your application: "));
        // cliSelect({
        //   values: ["MongoDB", "PostgreSQL", "Firebase", "Redis", "MySQL"],
        //   valueRenderer: (value, selected) => {
        //     if(selected) {
        //       return chalk.blue(value)
        //     }
        //     return value;
        //   }
        // }).then(res => console.log("The result/value:", res, "n"))
        await inquirer.prompt(questions).then((answers) => {
          console.log(chalk.green(`The package ${answers.option} will be downloaded`));
        }).catch(err => {
          console.log("There was an error");
        })

        packages.push("express", "ejs", "dotenv", "cors", "body-parser");
        dependencies = await installPackages(packages);
        renderTemplate("./bin/templates/_index.ejs", "./", jsonFile.main || "index.js", {path: "/public/index.html"});
      } else if(argv._.length > 1) {
        //get all the arguments after the first ('create-node-app') argument to get all packages
        packages = argv._.slice(1);
        dependencies = await installPackages(packages);
        createFile("./", jsonFile.main || "index.js", "//This is the server file");
      }
      createFolder("./", "public", rl);
      renderTemplate("./bin/templates/_indexhtml.ejs", "./public/", "index.html", jsonFile);
      renderTemplate("./bin/templates/_styles.ejs", "./public/", "styles.css", "");
      renderTemplate("./bin/templates/_app.ejs", "./public/", "app.js", "");
    }
    
    //if the y flag is used
    let jsonFile;
    if(argv.y) {
      (await execa("npm init -y")).stdout;
    } else {
      // await execa("npm init");
      execSync('npm init', {stdio: 'inherit'})
    }
    console.log("The package.json file has been created");
    jsonFile = JSON.parse(fs.readFileSync("./package.json"))
    setup(jsonFile);

    createFile("./", ".env", "");
    createFile("./", ".gitignore", "node_modulesn.env");
    console.log("Done");
  }
});

This is what the output looks like when I run the command create create-node-app -y (This runs the npm init -y command to make the default package.json library and installs predefined packages but asks what database to include):

When I press the arrow keys to select a database:

When I press “enter” to select an option:

As you can see I also tried using cli-select package but I faced the same issue so I am not using the package correctly but I don’t know where am I missing?

Other functions like creatFolder, createFile, and renderTemplate do exactly what the name says. (renderTemplate renders an ejs template)

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật