The file is messed up(backend folder i mean)

`

node:internal/modules/cjs/loader:936
  throw err;
  ^

Error: Cannot find module 'express'
Require stack:
- C:\Users\iftkh\app\Backend\index.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\iftkh\app\Backend\index.js:1:17)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ 'C:\\Users\\iftkh\\app\\Backend\\index.js' ]
}

whats the fix

I hope running npm install will fix the issue.

Hi, I’ve noticed you have helped a few people with backend issues, when I run “node index.js” I get an error code MODULE_NOT_FOUND. Any ideas what this could be? Thanks

Hi. I’d suggest that you create a new thread covering the following questions/points and share the link to that thread here. Your query will get more attention and faster response as the community is really helpful here :slight_smile:

  1. what operating system are you using?
  2. have you installed node on your system? Which version? (run node --version from your terminal/commandline)
  3. please share the complete error message

Hi,

I am using Windows 10, the node version I have installed is V16.17.1, and the complete error message is as follows:

Error: Cannot find module ‘C:\Users\Noah\Desktop\Backend\index.js’
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:956:15)
at Function.Module._load (node:internal/modules/cjs/loader:804:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47 {
code: ‘MODULE_NOT_FOUND’,
requireStack:
}

Can you confirm that a node.js file exists at this location: C:\Users\Noah\Desktop\Backend\?

Also, please share the code of your index.js.

I am not sure how I would check if its specifically at that directory, as for the index.js code see below:

const express = require(“express”);

const categories = require(“./routes/categories”);

const listings = require(“./routes/listings”);

const listing = require(“./routes/listing”);

const users = require(“./routes/users”);

const user = require(“./routes/user”);

const auth = require(“./routes/auth”);

const my = require(“./routes/my”);

const messages = require(“./routes/messages”);

const expoPushTokens = require(“./routes/expoPushTokens”);

const helmet = require(“helmet”);

const compression = require(“compression”);

const config = require(“config”);

const app = express();

app.use(express.static(“public”));

app.use(express.json());

app.use(helmet());

app.use(compression());

app.use(“/api/categories”, categories);

app.use(“/api/listing”, listing);

app.use(“/api/listings”, listings);

app.use(“/api/user”, user);

app.use(“/api/users”, users);

app.use(“/api/auth”, auth);

app.use(“/api/my”, my);

app.use(“/api/expoPushTokens”, expoPushTokens);

app.use(“/api/messages”, messages);

const port = process.env.PORT || config.get(“port”);

app.listen(port, function() {

console.log(Server started on port ${port}...);

});

I have now fixed the error, I relocated the file and manually reinstalled the sharp dependency. This solved my issue.

That’s strange. I initially thought it was due to node not set up properly or the index.js was at some other location.
I do recall I faced some issue related to sharp package while running a node server.

Yea from what I can tell there is a multitude of potential issues that can arise from that stage of the series, my solution was taken from 2 different solutions that worked for others on here. It seems very volatile all together for so many people to have so many different issues