Home > Enterprise >  NPM packages are not running with the node.js
NPM packages are not running with the node.js

Time:07-24

enter image description here

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

enter image description here

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

CodePudding user response:

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.

  • Related