Ameer
Ameer

Reputation: 2000

Unexpected command line syntax error in node js

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

Upvotes: 0

Views: 1278

Answers (2)

Amit Kumar Gupta
Amit Kumar Gupta

Reputation: 7413

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

Upvotes: 1

hong4rc
hong4rc

Reputation: 4113

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.

Upvotes: 0

Related Questions