0

I´m writing a Web MMO with Node.js and for debug and maintenance reasons i would love to have the ability to open my SSH connection, where i also start my server, and write a command like "logout all". So what are my options to get command prompt input and use it while my server runs?

Example: I start my server with "node app.js" - server starts. Now i want to write something into the command prompt - how do i get said input so i can use it in my code?

I was trying to read into node.js-readline but i cant seem to find much about it and everything that i found about it needs a "question" to be asked so it can get the input.

I would love to have something like this: var command = getCommandlineInput(); //command = "logout all" It need to get any input any time. A callback function would be good aswell, so i can direktly run it throu a checkCommand() function.

Toastbot
  • 77
  • 9

1 Answers1

0

So i just figured out how to do this:

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

readline.on('line', (input) => {
    useCommand(input);
});

function useCommand (input)
{
    switch (input) {
        case "show userlist":
                CMD_showUserlist();
            break;
    }
}

First we initiate readline. With readline.on we listen for any input you type into the command prompt. useCommand() takes this input and chose what function to run. How to work with the given input string is up to you, in my example i just made a hard coded command "show userlist".

Toastbot
  • 77
  • 9