我如何运行该脚本?

我如何运行该脚本?

我正在尝试安装 BadgeKit API,并且需要运行此命令:

#!/usr/bin/env node

var assert = require('assert');
var fs = require('fs');
var path = require('path');
var util = require('util');
var optimist = require('optimist');
var migrate = require('db-migrate');
var log = require('db-migrate/lib/log');
var mysql = require('mysql');
var migrations = require('../app/lib/migrations');
var db = require('../app/lib/db');

process.on('uncaughtException', function(err) {
  log.error(err.stack);
  process.exit(1);
});

var argv = optimist
    .default({
      verbose: false
    })
    .usage('Usage: db-migrate [up|down|create] migrationName [options]')

    .describe('count', 'Max number of migrations to run.')
    .alias('c', 'count')
    .string('c')

    .describe('dry-run', "Prints the SQL but doesn't run it.")
    .boolean('dry-run')

    .describe('verbose', 'Verbose mode.')
    .alias('v', 'verbose')
    .boolean('v')

    .alias('h', 'help')
    .alias('h', '?')
    .boolean('h')
    .argv;

if (argv.help || argv._.length == 0) {
  optimist.showHelp();
  process.exit(1);
}

global.verbose = argv.verbose;
global.dryRun = argv['dry-run'];
if(global.dryRun) {
  log.info('dry run');
}

function executeCreate() {
  if(argv._.length == 0) {
    log.error("'migrationName' is required.");
    optimist.showHelp();
    process.exit(1);
  }

  argv.title = argv._.shift();
  migrate.createMigration(argv.title, migrations.dir, function(err, migration) {
    assert.ifError(err);
    log.info(util.format('Created migration at %s', migration.path));
    process.exit(0);
  });
}

function onComplete(err) {
  assert.ifError(err);
  log.info('Done');
  process.exit(0)
}

function run() {
  var action = argv._.shift();
  switch(action) {
    case 'create':
      executeCreate();
      break;
    case 'up':
    case 'down':
      argv.config = db.getDbConfig();
      if(argv.verbose) {
        log.info("Using settings:", argv.config);
      }
      if(argv._.length > 0) {
        argv.destination = argv._.shift().toString();
      }
      if(action == 'up') {
        migrations.up(argv, onComplete);
      } else {
        migrations.down(argv, onComplete);
      }
      break;

    default:
      log.error('Invalid Action: Must be [up|down|create].');
      optimist.showHelp();
      process.exit(1);
      break;
  }
}

run();

我收到此错误:

{ [Error: getaddrinfo ENOTFOUND]
  code: 'ENOTFOUND',
  errno: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  fatal: true }
[ERROR] Error: getaddrinfo ENOTFOUND
    at errnoException (dns.js:37:11)
    at Object.onanswer [as oncomplete] (dns.js:124:16)
    --------------------
    at Protocol._enqueue (/root/badgekit-api/node_modules/mysql/lib/protocol/Pro                                                                                                                     tocol.js:110:26)
    at Protocol.handshake (/root/badgekit-api/node_modules/mysql/lib/protocol/Pr                                                                                                                     otocol.js:42:41)
    at Connection.connect (/root/badgekit-api/node_modules/mysql/lib/Connection.                                                                                                                     js:81:18)
    at Connection._implyConnect (/root/badgekit-api/node_modules/mysql/lib/Conne                                                                                                                     ction.js:222:10)
    at Connection.query (/root/badgekit-api/node_modules/mysql/lib/Connection.js                                                                                                                     :137:8)
    at Class.Base.extend.runSql (/root/badgekit-api/node_modules/db-migrate/lib/                                                                                                                     driver/mysql.js:246:34)
    at Class.Base.extend.createTable (/root/badgekit-api/node_modules/db-migrate                                                                                                                     /lib/driver/mysql.js:144:10)
    at Class.module.exports.Class.extend.createMigrationsTable (/root/badgekit-a                                                                                                                     pi/node_modules/db-migrate/lib/driver/base.js:72:10)
    at /root/badgekit-api/app/lib/migrations.js:16:23
    at /root/badgekit-api/node_modules/db-migrate/index.js:10:5

我怎样才能解决这个问题?

相关内容