Skip to content

Instantly share code, notes, and snippets.

@elrrrrrrr
Created August 15, 2014 06:15
Show Gist options
  • Save elrrrrrrr/07d2e8390aeee0787ddf to your computer and use it in GitHub Desktop.
Save elrrrrrrr/07d2e8390aeee0787ddf to your computer and use it in GitHub Desktop.
加载node模块
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