'Nodejs can't find file

I have script.js on desktop and test.js in a folder on desktop.

Case 1

When I write node script.js in Mac terminal, I get this error:

> node:internal/modules/cjs/loader:942
  throw err;
  ^
Error: Cannot find module 
......
  code: 'MODULE_NOT_FOUND',
  requireStack: []

Case 2

When I copy paste the path of script.js (the file on desktop) node /Users/Leah/Desktop/script.js, it runs fine.

Case 3

However, if I copy paste the path of test.js (the file in a folder on desktop) node /Users/Leah/Desktop/JavaScript projects/test.js, it returns the same thing as in Case 1.

I looked up on google but couldn't find a solution. Could anyone please help me? (npm is installed as well)

node:internal/modules/cjs/loader:942
throw err; 
^
Error: Cannot find module '/Users/Leah/script.js' at Module._resolveFilename 
(node:internal/modules/cjs/loader:939:15) at Module._load
(node:internal/modules/cjs/loader:780:27) at Function.executeUserEntryPoint
[as runMain] (node:internal/modules/run_main:77:12) at 
ode:internal/main/run_main_module:17:47 { code: 'MODULE_NOT_FOUND', requireStack: [] }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source