Created
September 15, 2013 22:45
-
-
Save edinella/6574947 to your computer and use it in GitHub Desktop.
Node.js "require" with specific paths array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // obtém pacote nos paths específicos | |
| var requireAt = function requireAt(packageName, paths) { | |
| // armazena paths originais deste ambiente, preservando-os | |
| var originalPaths = module.paths; | |
| // define paths para este ambiente, sobreescrevendo atuais | |
| module.paths = paths; | |
| // obtém modulo nos paths deste beat | |
| var pkg = require(packageName); | |
| // restaura paths originais | |
| module.paths = originalPaths; | |
| // retorna o pacote desejado | |
| return pkg; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment