I'm in the process of developing a text-based game through the console, utilizing an NPM package known as "prompts" to prompt the user for input. One specific question it asks is, "What OS do you want to run?" and returns the selection as JSON data. For instance, if the user chooses "OS 1", the response would be { Bootup: "StartOS1" }. My goal is to execute different JavaScript files based on this selection using an if statement:
if(Bootup == "StartOS1") {
// Insert code to execute another JS file here.
}
However, I'm uncertain what to include within this section.
Initially, I attempted to achieve this task with the help of a separate NPM package titled shelljs, which allows for shell execution:
const shell = require('shelljs')
if(Bootup == "StartOS1") {
shell.exec('node OS1.js')
}
Unfortunately, this approach resulted in my shell becoming unresponsive and stuck at a blank line indefinitely, requiring a system restart. This situation highlights the essence of what I'm striving to accomplish.