-
-
Save elrrrrrrr/07d2e8390aeee0787ddf to your computer and use it in GitHub Desktop.
加载node模块
This file contains 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
var mod = require('module'); | |
module.exports = function module_exist(name){ | |
/** | |
* This is UGLY but since we're not allowed to require 'native_module' | |
* this is the only way to test if a native module (or non-native module) exist. | |
*/ | |
try{ | |
require(name); | |
} catch(err){ | |
if(err.code === 'MODULE_NOT_FOUND'){ | |
return false; | |
} | |
} | |
return true; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment