Ammad Ali
Ammad Ali

Reputation: 17

NPM packages are not running with the node.js

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

I already tried reinstalling it. I used npm install prompt -sync to use it with JavaScript inside Visual Studio Code but I don't know where I am going wrong. I have already added the variables in system advanced setting.

Visual Studio Code error message if I try to use prompt or alert inside and run through code runner extension:

Upvotes: -1

Views: 344

Answers (1)

Nabeel Ahmed
Nabeel Ahmed

Reputation: 154

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.

Upvotes: 2

Related Questions