This commit is contained in:
idori
2017-10-15 23:22:42 +03:00
parent ee6a934a42
commit a27153011c

View File

@ -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/>