mirror of
https://github.com/goldbergyoni/nodebestpractices.git
synced 2025-11-01 18:46:54 +08:00
require
This commit is contained in:
@ -296,9 +296,11 @@ Text here...
|
||||
|
||||
<br/><br/>
|
||||
|
||||
## ✔ 3.7 Put All Requires at the top
|
||||
## ✔ 3.7 Requires come first.
|
||||
|
||||
**TL;DR:** This simple best practice will help you easily and quickly tell the dependencies of a file right at the beginning.
|
||||
**TL;DR:** Require modules at the beginning of each file, before and outside of any functions. This simple best practice not only will help you easily and quickly tell the dependencies of a file right at the top, but also avoid a couple of potentail problems.
|
||||
|
||||
**Otherwise** Requiers are run syncronously by Node JS. If they are called from withing a function, it may block other requests from being handled at a more critical time. Also, if a required module (or any of its own dependencies) throws an error and crashes the server, it is best to find out about it as soon as possible, which might not be the case if that module is required from within a function.
|
||||
|
||||
|
||||
<br/><br/><br/>
|
||||
|
||||
Reference in New Issue
Block a user