2
node app.js
node:internal/modules/cjs/loader:998
  throw err;
  ^

Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\app.js'
    at Module._resolveFilename (node:internal/modules/cjs/loader:995:15)
    at Module._load (node:internal/modules/cjs/loader:841:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []

i was trying to get the node code to work basically node app.js

Ayam Dash
  • 21
  • 1
  • 2

3 Answers3

0

Look into your project directory where you initialized node app.js. The issue is that you're not in the project directory where this file exists. Go into the project directory and launch your node app.js.

90% sure, hopefully this will fix it.

node_modules
  • 4,790
  • 6
  • 21
  • 37
0

This error usually occurs when you're not in the right folder. Here you're in C:\Program Files\nodejs\node_modules\npm and you're trying to run your file App.js which is stored elsewhere on your computer.

I'd recommend going through these simple steps to fix the problem: (let's say you want Node to run your file App.js.

  1. Check whether or not your file exist in the current working directory (the error says it isn't there) with one of the commands:
    ls (bash, shell, powershell) or dir (cmd).
  • If your file (App.js) is listed on the output of the above command, then check the spelling and make sure the case exactly matches what you provided to node. That is you command must be node App or node App.js and not node app.js or node aPP.js...

  • If your file isn't listed (what is the more probable outcome) then go to step 2.


  1. Get the full path of the folder containing your file (App.js) from your file explorer.
  • On windows, just open the folder containing your file and copy the content of the address bar.
  • On Linux, refer to this question.
  • On Mac, refer to this other question

  1. In your terminal navigate to the above folder with the command
    cd copied_path.

  1. Check again the content of the path to make sure your command line is opened in the right folder.

  1. Run node App.js
tem
  • 101
  • 4
0

I think the error is caused by the node_modules directory. In my case, I tried npm install with an old version of node(nodev12) for an app using nodev18. After I deleted nodev12, I also removed the node_modelues directory and ran npm install and it worked.