node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »



NGN System Utilities

Installation: npm install ngn-util.

Auto-install missing module.

The following code will automatically and synchronously install a module if it is not already installed. Supports global installs, which automatically links the global module to the current working directory. Supports alternative npm registry.

var util = require('ngn-util');
var uuid = util.require('node-uuid');




The system utilites also provide some wrappers around npm. This includes:

  • npm.install()
  • npm.installSync()
  • npm.installed()
  • npm.globalDirectory
  • npm.globalLink()
var util = require('ngn-util');
var config = {
  package: 'myModule',
  name: 'My Awesome Module', // <-- Descriptive name for module (used in CLI status) 
  global: false,
  registry: ''
// Install a module asynchronously 
// Install a module synchronously 
console.log(util.npm.globalDirectory); // Show the path to npm global 

To check if a module is already installed:

var util = require('ngn-util');

Returns an object like:

  global: false,
  local: true

The method can be passed an optional second argument of which directory should contain the module if installed locally.

Example: util.npm.installed('myModule','/path/to/my/project');

Wrapped Modules

tl;dr:This module auto-installs what NGN needs.

The NGN Utility library will manage certain module dependencies dynamically. For example, if var util = require('ngn-util'); util.execSync(...); is called, the utility will attempt to install the exec-sync module. If it is not found, it will be installed globally and a link will be created. This allows reuse of common modules throughout the NGN platform without adding redundant installations of the same modules (as is common many node modules). Of course, individual modules can be overridden as necessary.

The following modules are wrapped into the NGN utilities:

  • exec-sync (Execute commands synchronously... CLI-ONLY!)
  • bcrypt (strong encryption)
  • seq (flow control)
  • read (CLI prompt)
  • colors (colorized console output)
  • optimist (CLI argument utility)