简体   繁体   中英

Node.js execute Javascript file

This is a completely newbie question and I'm sure the solution is very easy but I don't get it.

I downloaded Node.js and put the command-tool file and the npm in my project file.

I created a file called example.js which contains

console.log("hello world");

Now I open the node file and type in

node example.js

And it shows me unexpected Identifier.

Thanks in advance.

Edit:

 node -v 

Shows node is not defined ?? .. I'm slightly confused.

Edit2: MAC IOS

Edit3: I installed it and the path was usr/local/bin am I allowed to just move the file?

Edit4: Thanks node -v works now. I opened it through the cmd tool

Edit5: okay now everything works.. I thought I have to work with the node cmd tool. Thanks for the quick help!

  1. Open terminal
  2. Go to the folder you have your example.js (use cd -command)
  3. type in terminal node example.js , press enter

You should not RUN node before typing node example.js

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