Getting values from Deno stdin

后端 未结 5 1097
梦毁少年i
梦毁少年i 2021-02-14 11:43

How can we get values from standard input in Deno?

I don\'t know how to use Deno.stdin.

An example would be appreciated.

5条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-14 11:55

    I have a small terminal sample to test with the Deno TCP echo server. It's something like:

    private input = new TextProtoReader(new BufReader(Deno.stdin));
    
    while (true) {
        const line = await this.input.readLine();
        if (line === Deno.EOF) {
            console.log(red('Bye!'));
            break;
        } else {
            // display the line
        }
    }
    

    The full project is on Github.

提交回复
热议问题