简体   繁体   中英

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM