javascript node.js读取命令行流

javascript node.js读取命令行流,node.js,Node.js,我有一个node.js脚本,它使用npm commander读取参数 像节点a.js-a“hello”-b“100” 但是我在向这样的服务器发送html数据时遇到了一个问题 node a.js-a“一些带有双引号和单引号的Html内容”-b“100” 我能想到的一个选择是发送类似EOL的邮件 node a.js -b "100" << EOL some Html content with double quotes and single quotes EOL node a.js-b

我有一个node.js脚本,它使用npm commander读取参数

节点a.js-a“hello”-b“100”

但是我在向这样的服务器发送html数据时遇到了一个问题

node a.js-a“一些带有双引号和单引号的Html内容”-b“100”

我能想到的一个选择是发送类似EOL的邮件

node a.js -b "100" << EOL
some Html content with double quotes and single quotes
EOL
node a.js-b“100”您可以通过以下方式使用内置的node.js模块:

const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
});

let html = ''

rl.on('line', (input) => {
    if (input === 'EOL')
        console.log('received html: ' + html)
    else
        html+= ' ' + input
});
使用
节点a.js-b“100”
调用,然后输入HTML,使用任意多行。
当输入EOL(单行)时,程序将考虑HTML输入已被完全提供。

查看“代码>进程。STDIN < /代码>,和/或模块<代码>读取行< /代码>;为什么不将html内容存储在文件中?此脚本将定期调用,不希望管理文件和维护相同的内容。。删除等。。