Addict Addict - 1 year ago 160
Node.js Question

Electron Readline

I'm trying to build an app using electron, it's designed to get a GUI later but for now i'm just trying to do this:

function test(){

console.log("In Test")

var readline = require('readline');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout

rl.on('line', function(line){


// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
app.on('ready', test);

On launching
npm start
, I see the "
In Test
" log, but when I type something in my shell, it's not returned to me as I need it to be by the Readline module.

Am I missing something ?

Answer Source

In Electron the console becomes the Chromium console which is not like the terminal you're used to. Readline is not going to work as far as I know. The blink console in Chromium does not support reading input this way. It operates more like a debug REPL where you can type JS code, inspect variables, etc. It's not for user input. I don't think you're going to be able to get input supplied from that console into stdin, which is where the readline module is waiting to see data.


I assumed OP was using the dev tools console expecting it to work like a shell. He was using it properly. The actual issue is a bug with node's readline module on Windows. Node devs are actively working to fix it. It's a regression bug that was fixed once before but appeared again in recent versions of node.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download