How to use npm - 10 common examples

To help you get started, we’ve selected a few npm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ether / etherpad-lite / src / node / hooks / express / tests.js View on Github external
pluginSpecs: function(callback){
        exports.getPluginTests(callback);
      }
    },
    function(err, results){
      var files = results.coreSpecs; // push the core specs to a file object
      files = files.concat(results.pluginSpecs); // add the plugin Specs to the core specs
      console.debug("Sent browser the following test specs:", files.sort());
      res.send("var specs_list = " + JSON.stringify(files.sort()) + ";\n");
    });

  });


  // path.join seems to normalize by default, but we'll just be explicit
  var rootTestFolder = path.normalize(path.join(npm.root, "../tests/frontend/"));

  var url2FilePath = function(url){
    var subPath = url.substr("/tests/frontend".length);
    if (subPath == ""){
      subPath = "index.html"
    }
    subPath = subPath.split("?")[0];

    var filePath = path.normalize(path.join(rootTestFolder, subPath));
    // make sure we jail the paths to the test folder, otherwise serve index
    if (filePath.indexOf(rootTestFolder) !== 0) {
      filePath = path.join(rootTestFolder, "index.html");
    }
    return filePath;
  }
github apmjs / apmjs / bin / cli.js View on Github external
npm.argv = conf.argv.remain
  if (npm.deref(npm.argv[0])) npm.command = npm.argv.shift()
  else conf.usage = true

  if (conf.version) {
    console.log(pkg.version)
    return errorHandler.exit(0)
  }

  if (conf.versions) {
    npm.command = 'version'
    conf.usage = false
    npm.argv = []
  }

  log.info('using', 'npm@%s', npm.version)
  log.info('using', 'node@%s', process.version)

  process.on('uncaughtException', errorHandler)

  if (conf.usage && npm.command !== 'help') {
    npm.argv.unshift(npm.command)
    npm.command = 'help'
  }

  // now actually fire up npm and run the command.
  // this is how to use npm programmatically:
  conf._exit = true
  npm.load(conf, function (er) {
    // this log is different from the one required by npm
    log.level = npm.config.get('loglevel')
    log.resume()
github pimatic / pimatic / ppm.js View on Github external
#!/usr/bin/env node
/*
  Modified version of https://github.com/npm/npm/blob/master/bin/npm-cli.js
  Copyright (c) npm, Inc. and Contributors
  Licensed on the terms of The Artistic License 2.0
  See https://github.com/npm/npm/blob/master/LICENSE
*/
var path = require("path");
var npm = require("npm");
var semver = require('semver');

if(!semver.satisfies(npm.version, '2.*')) {
  console.log("Error: npm version " + npm.version + " is not supported by ppm. "
    + "Please install npm v2 globally ('npm install -g npm@2') or locally in your "
    + "pimatic-app directory ('npm install npm@2'). See you again.");
  process.exit(1);
}

process.title = "ppm";

var log = require("npm/node_modules/npmlog");
log.pause() // will be unpaused when config is loaded.
log.info("it worked if it ends with", "ok");


var npmconf = require("npm/lib/config/core.js");
var errorHandler = require("npm/lib/utils/error-handler.js");
github pimatic / pimatic / ppm.js View on Github external
#!/usr/bin/env node
/*
  Modified version of https://github.com/npm/npm/blob/master/bin/npm-cli.js
  Copyright (c) npm, Inc. and Contributors
  Licensed on the terms of The Artistic License 2.0
  See https://github.com/npm/npm/blob/master/LICENSE
*/
var path = require("path");
var npm = require("npm");
var semver = require('semver');

if(!semver.satisfies(npm.version, '2.*')) {
  console.log("Error: npm version " + npm.version + " is not supported by ppm. "
    + "Please install npm v2 globally ('npm install -g npm@2') or locally in your "
    + "pimatic-app directory ('npm install npm@2'). See you again.");
  process.exit(1);
}

process.title = "ppm";

var log = require("npm/node_modules/npmlog");
log.pause() // will be unpaused when config is loaded.
log.info("it worked if it ends with", "ok");


var npmconf = require("npm/lib/config/core.js");
var errorHandler = require("npm/lib/utils/error-handler.js");

var configDefs = npmconf.defs;
github apmjs / apmjs / bin / cli.js View on Github external
if (conf.version) {
    console.log(pkg.version)
    return errorHandler.exit(0)
  }

  if (conf.versions) {
    npm.command = 'version'
    conf.usage = false
    npm.argv = []
  }

  log.info('using', 'npm@%s', npm.version)
  log.info('using', 'node@%s', process.version)

  process.on('uncaughtException', errorHandler)

  if (conf.usage && npm.command !== 'help') {
    npm.argv.unshift(npm.command)
    npm.command = 'help'
  }

  // now actually fire up npm and run the command.
  // this is how to use npm programmatically:
  conf._exit = true
  npm.load(conf, function (er) {
    // this log is different from the one required by npm
    log.level = npm.config.get('loglevel')
    log.resume()
    if (er) return errorHandler(er)

    Object.defineProperties(npm.commands, {
github apmjs / apmjs / bin / cli.js View on Github external
console.log(pkg.version)
    return errorHandler.exit(0)
  }

  if (conf.versions) {
    npm.command = 'version'
    conf.usage = false
    npm.argv = []
  }

  log.info('using', 'npm@%s', npm.version)
  log.info('using', 'node@%s', process.version)

  process.on('uncaughtException', errorHandler)

  if (conf.usage && npm.command !== 'help') {
    npm.argv.unshift(npm.command)
    npm.command = 'help'
  }

  // now actually fire up npm and run the command.
  // this is how to use npm programmatically:
  conf._exit = true
  npm.load(conf, function (er) {
    // this log is different from the one required by npm
    log.level = npm.config.get('loglevel')
    log.resume()
    if (er) return errorHandler(er)

    Object.defineProperties(npm.commands, {
      'install': {
        get: () => require('../src/commands/install.js')
github unicode-org / full-icu-npm / install-npm.js View on Github external
module.exports = function npmInstallNpm(fullIcu, advice) {
	var icupkg = fullIcu.icupkg;
	var icudat = fullIcu.icudat;
	// var nodever = fullIcu.nodever;
	// var icuver = fullIcu.icuver;
	
	var npm = require('npm');


	
	
	npm.load({}, function(err) {
		if(err) throw err;
		npm.commands.install([ icupkg ], function(err, data) {
			if(err) {
				console.log('Your ICU version may not be available in NPM yet..');
				throw err;
			}
			
	//		console.log("Installed " + data.length + " thing(s).");
			data.forEach(function(i) {
				var datPath = path.join(i[1],icudat);
				if(fs.existsSync(icudat)) {
					console.log(' √ ' + i[0] + ' : ' + icudat + " (existing symlink?)");
				} else if(!fs.existsSync(datPath)) {
					console.log(' • ' + i[0] + ' (no ' + icudat + ')');
				} else {
					try {
github hoodiehq / hoodie / lib / hoodie-log.js View on Github external
module.exports = function HoodieLog(name, couch_url) {
  var password;
  npm.load(function(error, npm) {
    password = npm.config.get(name + "_admin_pass");
  });

  return function hoodie_log() {
    // log as usual
    console.log.apply(this, arguments);

    // make a nice object!
    var log = {
      message: util.format.apply(this, arguments),
      time: new Date()
    };

    // send to couch
    request({
      url: couch_url + "/logs",
github arikon / npm2debian / lib / source.js View on Github external
function install_ (pkg, reg, seen, mustHave, pkglist, cb) {
  log.verbose(pkg, "install_")
  if (seen[pkg]) return cb() // repeat, skip it
  seen[pkg] = true

  // it's a local thing or a url if it has a / in it.
  if (pkg.indexOf("/") !== -1 || pkg === ".") {
    log.silly(pkg, "install local")
    return cache.add(pkg, finisher(pkg, reg, pkglist, cb))
  }

  // now we know it's not a URL or file,
  // so handle it like a tag, version, or range.
  pkg = pkg.split("@")
  var name = pkg[0]
    , defTag = npm.config.get("tag")
    , ver = pkg.slice(1).join("@").trim() || defTag
    , range = semver.validRange(ver)
github arikon / npm2debian / lib / source.js View on Github external
function _source(pkg, reg, pkglist, cb) {
    log.verbose(pkg, "_source");

    // it's a local thing or a url if it has a / in it.
    if (pkg.indexOf("/") !== -1 || pkg === ".") {
        log.silly(pkg, "install local");
        return cache.add(pkg, finisher(pkg, reg, pkglist, cb));
    }

    // now we know it's not a URL or file,
    // so handle it like a tag, version, or range.
    pkg = pkg.split("@");
    var name = pkg[0],
        defTag = npm.config.get("tag"),
        ver = pkg.slice(1).join("@").trim() || defTag,
        range = semver.validRange(ver),
        exact = semver.valid(ver),
        tag = !exact && !range && range !== "" && ver,