Search code examples
reactjsnode.jsexpress

Node.js v20.12.2 [nodemon] app crashed - waiting for file changes before starting


I was following a tutorial on YouTube of freecodecamp with the title "MERN Stack Tutorial - Book Store Project" I am trying to run it on port 5555 I am still at the start of project just trying to check if the server is running or not here is the link https://www.youtube.com/watch?v=-42K44A1oMA And the problem is I am facing an issue after running the command "npm run dev" as I am getting this error: Node.js v20.12.2 [nodemon] app crashed - waiting for file changes before starting... screenshot for referenceerror screenshot

package.json code snippet

{
  "name": "backend",
  "version": "1.0.0",
  "description": "",
  "type": "module",
  "main": "index.js",
  "scripts": {
    "start": "node index.js",
    "dev": "nodemon index.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.19.2",
    "nodemon": "^3.1.0"
  }
}

index.js code snippet

import express from "express";
import { PORT } from "./config";

const app = express();

app.listen(PORT, () => {
    console.log("App is listening to port: ${PORT}");
});

config.js code snippet

import express from "express";
import { PORT } from "./config";

const app = express();

app.listen(PORT, () => {
    console.log("App is listening to port: ${PORT}");
});

I have tried a lot of solutions from various sites on the internet, but still facing the issue, can anyone help me with this? I have tried ending the nodejs from the task manager but it did not work updated the nodejs didn't work removed cache but it did not work uninstalled and installed again but it did not work

I am using Windows


Solution

  • Your import is wrong. You should import ./config.js in index.js:

    import { PORT } from "./config.js";
    

    Also please note that your code snippets are the same.