Does Node run all the code inside required modules?

后端 未结 4 1529
清酒与你
清酒与你 2021-02-18 23:55

Are node modules run when they are required?

For example: You have a file foo.js that contains some code and some exports.

When I import the file by running the

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-19 00:53

    Only in the sense that any other JS code is run when loaded.

    e.g. a function definition in the main body of the module will be run and create a function, but that function won't be called until some other code actually calls it.

提交回复
热议问题