I think this is a common question back to the time Node.js was going trend, so just Google and you will find a lot. Also reading source code will help since it's in JavaScript.
So in CommonJS the "require" looks up modules in current directory and parent directories. It will scan the innermost directory first, if not found, it goes to the parent directory, and repeats until found of failed.