My app should print logs and run a node.js REPL. But logs mess up the REPL, so I tried to run the REPL in another TTY.
Here is a sample code:
// app.js
const fs = require('fs')
const repl = require('repl')
const getTTYFile = () => '/dev/pts/4' // TODO
const TTYFile = getTTYFile()
let read = fs.createReadStream(TTYFile)
let write = fs.createWriteStream(TTYFile)
repl.start({
input: read, output: write,
terminal: true, useColors: true
})
setInterval(() => console.log('I am log'), 1000)
I opened a terminal tab without shells in KDE. Then I started my nodejs app:
konsole --new-tab --hold -e tty # outputs `/dev/pts/4`
node app.js
Here are the problems:

How should I fix my code?