Welcome to the Linux Foundation Forum!

Chapter 7: Node's Module Systems / Detecting Main Module in CJS

The screenshot at the end includes a comment that inaccurately equates the commands 'node index.js' and 'npm start'. Although both commands initiate the execution of the index.js script, their outputs differ. Running 'npm start' precedes the script's output with the package and command names, unlike the direct 'node index.js' command.

For instance:

Executing node index.js displays:

{"level":30,"time":1712053992025,"pid":35906,"hostname":"jumbo","msg":"MY-PACKAGE STARTED"}

While npm start results in:

my-package@1.0.0 start
node index.js

{"level":30,"time":1712054145804,"pid":35938,"hostname":"jumbo","msg":"MY-PACKAGE STARTED"}

Additionally, it's worth noting that executing 'node .' in the package directory will run the script defined in the 'main' field of project.json, producing an output identical to running the script directly with the node command.

Comments

  • xdxmxc
    xdxmxc Posts: 157

    thanks I'll give it a look next time I review it

Categories

Upcoming Training