Skip to content

Instantly share code, notes, and snippets.

@ceberous
Created May 31, 2018 21:01
Show Gist options
  • Select an option

  • Save ceberous/a5c23d5f21fdbd034ebe89d77fc3e51d to your computer and use it in GitHub Desktop.

Select an option

Save ceberous/a5c23d5f21fdbd034ebe89d77fc3e51d to your computer and use it in GitHub Desktop.
Returns Node Global Path
const cp = require( "child_process" );
function get_node_global_path() {
try {
const output = cp.spawnSync( "npm" , [ "root" , "-g" ] , { encoding : "utf8" } );
return output.stdout.trim();
}
catch( error ) { console.log( error ); process.exit( 1 ); }
}
const NodeGlobalPath = get_node_global_path();
// const path = require( "path" );
// const request = require( path.join( NodeGlobalPath , "request" ) );
// const cheerio = require( path.join( NodeGlobalPath , "cheerio" ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment