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
The error message suggests you entered
node index.js
from inside node.You should first exit node, then from the regular command prompt (bash, PowerShell, cmd.exe), enter
node index.js
.can you show me your package.json file ?