0

The below code works fine in browser but when I try to run via node (in command prompt), it give error : Uncaught SyntaxError: Unexpected identifier

Please find the screenshot attached for an error.

//index.js

// This is my first JS code
console.log('Hello World');
//index.html 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>Hello World</h1>  
    <script src="index.js"></script> 
</body>
</html>

enter image description here

2
  • 2
    are you in the right folder? what is result of dir command in cmd Commented May 5, 2022 at 12:55
  • Yes, the below is the result of dir 05-05-2022 17:12 <DIR> . 05-05-2022 17:01 <DIR> .. 05-05-2022 18:12 335 index.html 05-05-2022 18:12 72 index.js 2 File(s) 407 bytes 2 Dir(s) 343,672,176,640 bytes free Commented May 6, 2022 at 4:54

1 Answer 1

-1

Found the problem. I started a node then ran below commands:

node
node index.js

All I had to do is just go to the directory and run this single command >> node index.js

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

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.