Node.js inside require is declared at the beginning or called when in use?

  node.js, question

At present, I have seen two writing styles in the code, one is to declare a pile at the beginning of the file.require, one is when using directlyrequireCall, which of these two writing methods is better?

Writing in the beginning will be executed when the file is loaded. If writing in a function, it will not be executed until the function is called.

It looks neat at the beginning, usually the library can be written at the beginning.
Some internal modules in self-written applications will have very close dependencies. If they are written at the beginning, they will lead to circular dependencies. Therefore, other modules within functions will sometimes be considered to be require.