I just started learning JS and have been finding it difficult to run JS code using the node command on the terminal. I’ve tried everything but it doesn’t show anything. Using node command doesn’t show anything
What should I do?
Tried to re-install Node.js a couple of times but it still doesn’t work.
3
Answers
To print something on the terminal, use
console.log()
instead ofalert()
. For example, in your case, replacealert(message)
withconsole.log(message)
and then it will print on the terminal.There might be many issues while you try to run the node.js command.
First reason :- To use alert() you must link your tut1.js with your html file. in script tag.
second reason : – To print something on the terminal, use console.log() instead of alert(). For example, in your case, replace alert(message) with console.log(message) and then it will print on the terminal.
third reason:- check your package.json file. check the start key and its value
you can first create a file with names like index.js and enter this text in the terminal
but each time you run this command you can use nodemon
he will do it for you.
link info:[1]: https://nodemon.io/