0

I have been trying to run some node js files. I have checked the files and they seem to have no syntax errors whatsoever. However, upon running the file on the node js command line i get this error

node first.js
 ^^^^^

SyntaxError: Unexpected identifier

Lately, I have also been unable to run my apache web server from XAMPP. Could this be a port assignee error. Or is it something else. I have also, checked the directory of the file and it checks out

Some help would be greatly appreciate

7
  • Does your "JavaScript" source file literally say node first.js? Commented Sep 24, 2018 at 22:43
  • No i simply ran node first.js on my node.js command line Commented Sep 24, 2018 at 22:44
  • You need to run the command node first.js as a command from the system command line. Once you start Node, you're in the Node repl and it expects you to type JavaScript statements. Commented Sep 24, 2018 at 22:54
  • So do I first write node. Then when this > appears I then type node first.js. Commented Sep 24, 2018 at 22:56
  • 1
    Check your PATH variables (System Properties > Advanced > Environment Variables) Commented Sep 24, 2018 at 23:05

2 Answers 2

1

When you're inside node's CLI, you can run JS or rather node supported instructions. Unfortunately, there is no global variable or keyword with name "node". If you want to run "first.js", you'll have to come out from node's cli and then run the command.

enter image description here

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

0

You can't run file with node first.js inside file js

  • node is undefined
  • That is't right syntax

If you want run first.js file, you can include it with require

let first = require('first);

but this way run it once (first time call it), you can use method inside first.js with export(or module.exports) of first.js.

But you just want call and run first.js, you can use child_process.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.