skip to Main Content

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’

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!)

2

Answers


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

    PS C:gitfoo> 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.

    Login or Signup to reply.
  2. can you show me your package.json file ?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search