Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Cannot find module 'readline-sync' : Node.js

I have never used node.js before, and I have been researching the answer to this question, but I have had no luck.

I am trying to allow the user to enter an input number (and honestly have no idea how to do this). Upon some research I tested a very simple input/output code:

var readline = require('readline-sync');

var term1 = readline.question("Please enter your first binary term: ");

console.log("your number : " + term1);

But when I try this I am getting the error:

module.js:550
throw err;
^

Error: Cannot find module 'readline-sync'
at Function.Module._resolveFilename (module.js:548:15)
at Function.Module._load (module.js:475:25)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/<name>/eclipse-workspace/319/SE319Assignment4/binaryCalc.js:1:78)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)

I was wondering if anyone can help me figure out why readline-sync cannot be read, or if there is a better way to write this simple input/output code in general! Thanks

like image 913
user10380644 Avatar asked Oct 29 '25 19:10

user10380644


2 Answers

if you don't have the dependency listed in your package.json file, try running this command from your cmd (cd into the directory where binaryCalc.js is located at):

npm install --save readline-sync

if you do have it in there, just try

npm install
like image 200
George Neto Avatar answered Nov 01 '25 08:11

George Neto


Yes you should create a dependency first So for that just open your folder where your js file is there through terminal. And just follow the following steps. . npm init . npm install readline-sync --save and after this just try to run your code It will definately not show any error

like image 22
Anurag Avatar answered Nov 01 '25 08:11

Anurag



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!