简体   繁体   English

如何将命令传递到node.js服务器?

[英]how to pass commands to a node.js server?

I have a question about running a node.js server. 我对运行node.js服务器有疑问。 After I have started a server using node server.js , I want to pass a javascript command to the running server. 使用node server.js启动服务器后,我想将javascript命令传递给正在运行的服务器。 In the same manner that the developer tools console works in a browser, I want to be able to enter a command and have the server execute it. 与开发人员工具控制台在浏览器中工作的方式相同,我希望能够输入命令并使服务器执行该命令。 For example, if I have a game server running, and I want to kill a certain player, I could enter into some sort of CLI player.kill(); 例如,如果我有一个运行中的游戏服务器,并且想杀死某个玩家,则可以输入某种CLI player.kill(); and the server will execute that command as it is entered. 服务器将在输入时执行该命令。 Is this possible? 这可能吗? thanks. 谢谢。

You can use VorpalJS for this scenario. 您可以在这种情况下使用VorpalJS Vorpal is a framework for building immersive CLI applications built on an interactive prompt provided by inquirer.js. Vorpal是一个用于构建沉浸式CLI应用程序的框架,该框架基于inquirer.js提供的交互式提示构建。

 const vorpal = require('vorpal')(); vorpal .command('mycommand1', 'Outputs "bar".') .action(function(args, callback) { this.log('bar'); callback(); }); vorpal .delimiter('mygame$') .show(); 
When you execute the above script it creates a new prompt "mygame$" then you can execute the command "mycommand1" in that prompt interactively which can then be passed on to your server. 当您执行上述脚本时,它将创建一个新的提示“ mygame $”,然后您可以在该提示中以交互方式执行命令“ mycommand1”,然后将其传递给您的服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM