All he had to do was run `node index.mjs` or `npm run start` to have his index recognized as a module. Node DOES not read package.json, npm (node package manager) does. Node is not the package manager, so of course changes to package.json won't affect running `node index.js` However, node recognizes the file extension mjs as a module and will execute it as such. So renaming the extension of the script would work. Alt…
It only makes sense because you understand the decisions behind it. Try teaching JS to someone with little experience — they don’t care that the browser wants one kind of module and Node wants another. They don’t know what a module is, they just want their code to run
which is why js is not a good language to start teaching someone without experience in another language (including the ecosystem).
To learn js, it is necessary to learn about the module system that evolved from the browser (and the hacks made in the past, prior to having a module system). Then you must learn that node.js and npm, and optionally, webpack and/or other packing tools.
It's very convoluted, and unnecessarily complex. However, this complexity isn't entirely one entity's fault. I think you'd find similar complexity in java, in the early years, around the dependency management ecosystem, before the advent of maven 2.
Of course, you can just skip all of that, and go with the old C/C++ model, which is just copy/paste the code into a file in your project. For someone looking to test out some code they randomly found, this is probably the most recommended route imho.