Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: npm/npm
...
head fork: ncb000gt/npm
Checking mergeability… Don't worry, you can still create the pull request.
  • 1 commit
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Commits on Oct 19, 2010
@ncb000gt ncb000gt Added a convenience method to get the active version of a module.
Signed-off-by: Nick Campbell <ncampbell@siteworx.com>
09603c2
Showing with 19 additions and 0 deletions.
  1. +19 −0 npm.js
View
19 npm.js
@@ -13,6 +13,25 @@ npm.commands = {}
npm.ELIFECYCLE = {}
npm.E404 = {}
+npm.getActiveVersion = function(module, cb) {
+ if (!cb) throw new Error('Requires a callback')
+ require("./lib/utils/read-installed")(module, function(err, data) {
+ data = data[module]
+ if (data) {
+ for (var p in data) {
+ var o = data[p]
+ if ('active' in o && o.active) {
+ cb(null, p)
+ return;
+ }
+ }
+ cb('No version found')
+ } else {
+ cb('Module is not installed')
+ }
+ })
+}
+
if (process.getuid() === 0) {
log.error( "\nRunning npm as root is not recommended!\n"
+ "Seriously, don't do this!\n", "sudon't!")

No commit comments for this range

Something went wrong with that request. Please try again.