I installed Node.js (LTS version) via their website on my Windows, created a new folder called "mynode" and a text file inside this folder called "hellonode.js, opened the command prompt and changed to the directory "mynode" but when I run node hellonode.js
, I get the "Cannot find module" error.
C:\Users\Mina>cd mynode
C:\Users\Mina\mynode>node hellonode.js
node:internal/modules/cjs/loader:1080
throw err;
^
Error: Cannot find module 'C:\Users\Mina\mynode\hellonode.js'
←[90m at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)←[39m
←[90m at Module._load (node:internal/modules/cjs/loader:922:27)←[39m
←[90m at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)←[39m
←[90m at node:internal/main/run_main_module:23:47←[39m {
code: ←[32m'MODULE_NOT_FOUND'←[39m,
requireStack: []
}
Node.js v18.16.1
I already searched for solutions and I tried some suggestions:
Frist I deinstalled Node.js and reinstalled it, but nothing changed.
As suggested here: "internal/modules/cjs/loader.js:582 throw err" I ran npm init
so that a "package.json" file was created (I left everything as in the default settings.) and then npm install
and afterwards npm start
, but this got me the "Missing script: "start"" error, so that I added "start": "node hellonode.js"
under "scripts" in the "package.json" file, and run npm start
again, but this again got me the same main error from above: Cannot find module 'C:\Users\Mina\mynode\hellonode.js'.
What else can I do? Am I missing a step?
Here you can see the files in the path:
Verzeichnis von C:\Users\Mina\mynode
03.07.2023 18:16 <DIR> .
03.07.2023 18:16 <DIR> ..
03.07.2023 18:01 593 hellonode.js.txt
03.07.2023 18:17 199 package-lock.json
03.07.2023 18:16 202 package.json
3 Datei(en), 994 Bytes
2 Verzeichnis(se), 3.924.852.736 Bytes frei