0

Good morning, beginner here.

Im reading a book where the author tells me to run a command from the command line to execute a program made in js, source:https://eloquentjavascript.net/20_node.html#h_TUzbi7lU/0

I've downloaded the lastest recommended version of nodejs (12.13.0 LTS), made the js file the book tells me to run (I made it in visualstudio because renaming a .txt file with the code to .js didn't do the job) and copy pasted it in the folder where the nodejs folder is, ran the command (ran several others that i thought would work as well) and i get this error:

nodeterminal

This other thread had a similar problem with a solution, while it might solve the problem of running the program, it doesn't run it in the way the author of the book im reading tells me to, How to run a hello.js file in Node.js on windows?

JDCH
  • 43
  • 1
  • 6

2 Answers2

1

Hello and welcome to SO.

You seem to have run node then hello in the node REPL, which is, of course an undefined variable.

Exit out of node and run node hello.js. This will use node to execute the code in the hello.js file if you are in the same folder/directory as it.

psilocybin
  • 920
  • 5
  • 22
  • i did it this way and it ran the program, i still don't know why it wouldn't run the program when i use the command "$ node hello.js" – JDCH Oct 23 '19 at 11:47
0

Just close this node terminal and start a new command prompt from the desired location and run "node hello.js" in a single line.