Node.js user input wont work, readline-sync and error code 134

732 views Asked by At

I'm coding a project in node.js on vs code and need an user input for various functions. I tried many libraries such as readline-sync or prompt-sync-plus but none of them work for me. While using readline-sync I always get the error: Process exited with code 134 and can't figure out what I'm doing wrong:

import readlineSync from 'readline-sync';
const name = readlineSync.question("Whats the name of the movie?")
console.log(name)


"Error: Process exited with code 134"

Can someone help me?

I tried to update node.js and readline-sync but it wont help. I also tried the readlineSync.question function in a different file so that I can exclude my code from the equation but its still not working

2

There are 2 answers

1
Peter Zimmermann On

try using the built-in process.argv

https://nodejs.org/docs/latest/api/process.html#processargv

--> const userInput = process.argv.slice(number);

the number should be the number of arguments to be sliced off

--> node run myApplication "input1" --> number = 2

2
Nafiz Ahmed On

The readline-sync library provides a synchronous interface to read data from a readable stream. When using this library in a Node.js project, you may encounter a Process exited with code 134 error, which usually indicates a problem with the process running in the background.

Try to run this code separately and see if it works.

const readlineSync = require('readline-sync');

const name = readlineSync.question('What is your name? ');
console.log(`Hello, ${name}!`);