Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can't run "node index.js" due to a syntaxError

My code is the following;


import express from "express";

const app = express();
const port = 3000;

app.listen(port, () =>{
    console.log(`Server is running on ${port}.`)
});

I don’t understand what the issue is here. I’m following a course and followed the suggested steps yet I don’t really know how to fix this.

node index.js
^^^^^
Uncaught SyntaxError: Unexpected identifier ‘index’

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I thought it was a syntax error in the code but I can’t find anything. Error makes it sounds like it doesn’t like the name ‘index’ which I thought was funny.

I ran npm install express, then node, node index.js. Nothing super complex, is it possible the course is outdated and some syntax here is no longer valid? (Relatively new to coding, mainly in javascript!)

>Solution :

The error message suggests you entered node index.js from inside node.

PS C:\git\foo> node
Welcome to Node.js v20.11.0.
Type ".help" for more information.
> node index.js
node index.js
     ^^^^^

Uncaught SyntaxError: Unexpected identifier 'index'
>

You should first exit node, then from the regular command prompt (bash, PowerShell, cmd.exe), enter node index.js.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading