我可以使用node.js发送命令吗?

时间:2021-12-19 06:42:08

I'm running a node.js server using Terminal (Mac) and want to be able to emit messages to the client via the command line. Is this possible? I could code the messages part of it no problem, it's more how I can send something directly from the server to the client rather than from the client-server-client relationship I only understand at the moment.

我正在使用终端(Mac)运行node.js服务器,并希望能够通过命令行向客户端发送消息。这可能吗?我可以编写消息的一部分没问题,更多的是我可以直接从服务器发送到客户端,而不是从我目前只能理解的客户端 - 服务器 - 客户端关系。

1 个解决方案

#1


1  

This is probably what you're after if not let me know and I'll delete answer.

如果不让我知道,这可能是你想要的,我会删除答案。

Look into a module called Commander found here.

查看此处找到的名为Commander的模块。

It will allow you to build up a cli that you can then hook into your methods/prototypes etc.

它将允许您构建一个cli,然后您可以将其挂钩到您的方法/原型等。

For Matt :)

对于马特:)

var program = require('commander');
program.option('-s, --send', 'Send command');

#1


1  

This is probably what you're after if not let me know and I'll delete answer.

如果不让我知道,这可能是你想要的,我会删除答案。

Look into a module called Commander found here.

查看此处找到的名为Commander的模块。

It will allow you to build up a cli that you can then hook into your methods/prototypes etc.

它将允许您构建一个cli,然后您可以将其挂钩到您的方法/原型等。

For Matt :)

对于马特:)

var program = require('commander');
program.option('-s, --send', 'Send command');