How can Nodejs use Readline to avoid nested callbacks?

const fs = require("fs");
const readline = require("readline");
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

rl.question(":", (path) => {
  let file_path = path;
  rl.question(":", (name) => {
    let file_name = name;
    console.log(file_path);
    console.log(file_name);
    rl.close();
  });
});

is there a way to define global variables directly and then use readline to read in variables?

Jan.16,2022

you can try promisify , require ('util'). Promisify or bluebird promisifyAll method of util library) to see if you can convert question () to promise . If you can, you can use Async/Await syntax to avoid nested callbacks.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3e029-2c3c0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3e029-2c3c0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?