[英]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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.