I'm trying to take input using readline but am running into an unknown error after doing so. To make matters worse, my friend has no difficulties running the exact same piece of code on his device.
const { Octokit } = require("@octokit/rest");
const readline = require("readline");
const util = require('util');
const octokit = new Octokit();
const rl = readline.createInterface(process.stdin, process.stdout);
const question = util.promisify(rl.question).bind(rl);
const getUsername = async () => { return await question("Enter GitHub username: "); }
const getRepoData = async (uname) => { return await octokit.request("/users/" + uname + "/repos"); }
(async () => {
try {
console.log("checkpoint")
const uname = await getUsername();
console.log("checkpoint2")
console.log(uname);
var repoData = await getRepoData(uname);
repoData = repoData["data"]; // is a list of dictionaries, e.g. repoData[0]["name"]
console.log(repoData);
} catch (err) {
console.log("FAILED");
console.log(err);
} finally {
rl.close();
}
})()
My intention is that the program prints out information about a given GitHub user. However, running this program in console with node app.js results in
checkpoint
Enter GitHub username: fuzzyhappy
FAILED
fuzzyhappy
I have no idea why it's printing back the response to the question either.
catchblock. You have to remove the code in thetryblock line by line until you find the line producing the error. See this question for possible ways to debug your app. Note that without additional info about the error, nobody can help: "I have an unknown problem. Could you please solve it for me?"tryblock. If I hardcodeunameto a known username, it correctly retrieves information from GitHub. Sorry I left out that information!util.promisify. Figure out what's different on your machine compared to the one that runs fine. e.g: are they running different node versions? Possibly related question. In more detail, wouldutil.promisify(rl.question.bind(rl));work?