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.

Menu