0

I have a test.js file with the following content:

let i = ''
process.stdin.on('data', (c) => (i += c))
process.stdin.on('end', () => {
  const { EOL } = require('os')
  const lines = i.split(EOL) 
  console.log(lines)
})

I figured out that when I run this line bellow I read from input.txt and output to output.txt. Everything works just fine.

node test.js < input.txt > output.txt

However, I cannot find any info in node.js official docs about command line arguments like < and > . Am I looking in a wrong place? Is there somewhere a full list of possible arguments of this type and how to use them? Thanks.

Noob
  • 2,247
  • 4
  • 20
  • 31
  • 1
    ``<`` and ``>`` have special meanings in terminals, and what's happening here is unrelated to Node.JS. See [here](https://thoughtbot.com/blog/input-output-redirection-in-the-shell). – Take-Some-Bytes Dec 15 '20 at 05:05
  • Does this answer your question? [How to redirect output to a file and stdout](https://stackoverflow.com/questions/418896/how-to-redirect-output-to-a-file-and-stdout) – kmoser Dec 15 '20 at 06:25

1 Answers1

2

< and > are not command line arguments to node. Rather, in most shells, they are part of a feature known as I/O Redirection, which you can use to redirect the input and output of a program. According to the link above:

Redirection simply means capturing output from a file, command, program, script, or even code block within a script and sending it as input to another file, command, program, or script.

If you would like more information about actual command line arguments you can pass to node, you can run node --help or visit the official docs.