Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

NPM packages are not running with the node.js

enter image description here

Mysupername is the console.logged value that got printed out and not the expected output.

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I already tried reinstalling it. I used "npm install prompt -sync" to use it with javascript inside the vs vode but I don’t know where I am going wrong. I have already added the varaibles in system advanced setting.

Vs code error msg if I try to use "prompt" or "alert" inside and run through code runner extension

enter image description here

>Solution :

There’s a slight mistake with your code. Firstly, the reason why it is printing Mysupername to the console is because you provided console.log with a string. Instead just provide the variable name like this:

const superheroes = require('superheroes');

var Mysupername = superheroes.random();

console.log(Mysupername);

Now, the reason why prompt isn’t working is because you never imported the library into your code, you can do it by the following:

const prompt = require("prompt");

Final note, alert is only available when running javascript through a browser.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading