Skip to content

How to open exist tty using net.Socket ? #37780

Description

@oppai

Hi, there

I want to open exist tty using net.Socket. But I got an error like a below.

I have two questions.
First, how can I open tty using net.Socket module ?
Second, I success to open tty using tty.ReadStream like a them. But I didn't find it in document. It is trial function? (It is not safe to use in production?)

thank you

  • Node.js Version: v14.16.0
  • OS: MacOS / Linux
  • Scope (install, code, runtime, meta, other?): code
  • Module (and version) (if relevant): net.Socket
var fs = require('fs')
var net = require('net')

const fd = fs.openSync('/dev/ttys003', 'r+');
const tty = new net.Socket({fd, readable: true})
tty.on('data', (data) => {
  console.log(data)
})
TypeError [ERR_INVALID_FD_TYPE]: Unsupported fd type: TTY
    at createHandle (net.js:147:9)
    at new Socket (net.js:328:22)
    at Object.<anonymous> (/Users/hiroaki.murayama/progate/progate_ide/v2/src/runtime/sample.js:5:13)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'ERR_INVALID_FD_TYPE'

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to Node.js documentation.ttyIssues and PRs related to the tty subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions