Created
July 24, 2018 11:43
-
-
Save devarajchidambaram/f9b73b7542f8704afe77264ed3c753a3 to your computer and use it in GitHub Desktop.
get npm module version name
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
var path = require('path') | |
var fs = require('fs'); | |
function getNpmVersion(npmName) { | |
try { | |
var npmPath = require.resolve(npmName) | |
var npmDirName = path.dirname(npmPath) | |
return JSON.parse(fs.readFileSync(path.join(npmDirName, '/package.json'))).version; | |
} catch (e) { | |
console.log('error while resovle npm path', e.message) | |
} | |
return 'unknown' | |
} | |
module.exports = getNpmVersion; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment