Please ensure that you are running the node command in the same folder that the script.js
file exist. If you are opening command prompt from a different location and try running node script.js
, an error will be thrown as
internal/modules/cjs/loader.js:883 throw err; ^
Error: Cannot find module 'C:\yourpath\script.js' [90m at
Function.Module._resolveFilename
(internal/modules/cjs/loader.js:880:15)[39m [90m at
Function.Module._load (internal/modules/cjs/loader.js:725:27)[39m
[90m at Function.executeUserEntryPoint [as runMain]
(internal/modules/run_main.js:72:12)[39m [90m at
internal/main/run_main_module.js:17:47[39m { code:
[32m'MODULE_NOT_FOUND'[39m, requireStack: [] }
This indicates that the file doesnot exist in the desired path.
As per your question, you are running the command from C:\Users\User
, so your script.js
file must be there at the location C:\Users\User\script.js
. If your script.js is at some other location, say C:\Users\yourusername\somerandomfolderpath
, then you have to open your command prompt at that folder or go to that location using command prompt using these commads.
C:
cd C:\Users\yourusername\somerandomfolderpath
The first command takes you to the required drive (expecting it to be C drive here). The second command takes to the required folder in that drive.
After this you can run your script using.
node script.js