bin/index.js
function start(object, filename) {
  var port = process.env.PORT || argv.port
  var hostname = argv.host === '0.0.0.0' ? 'localhost' : argv.host

  for (var prop in object) {
    console.log(chalk.gray('  http://' + hostname +  ':' + port + '/') + chalk.cyan(prop))
  }

  console.log(
    '\nYou can now go to ' + chalk.gray('http://' + hostname + ':' + port + '/\n')
  )

  console.log(
    'Enter ' + chalk.cyan('`s`') + ' at any time to create a snapshot of the db\n'
  )

  process.stdin.resume()
  process.stdin.setEncoding('utf8')
  process.stdin.on('data', function (chunk) {
    if (chunk.trim().toLowerCase() === 's') {
      var file = 'db-' + Date.now() + '.json'
      _db.save(object, file)
      console.log('\nSaved snapshot to ' + chalk.cyan(file) + '\n')
    }
  })

  if (filename) {
    var router = jsonServer.router(filename)
  } else {
    var router = jsonServer.router(object)
  }

  var server = jsonServer.create()
  server.use(jsonServer.defaults)
  server.use(router)
  server.listen(port, argv.host)
}
function start(object, filename) {
  var port = process.env.PORT || argv.port
  var hostname = argv.host === '0.0.0.0' ? 'localhost' : argv.host

  for (var prop in object) {
    console.log(chalk.gray('  http://' + hostname +  ':' + port + '/') + chalk.cyan(prop))
  }

  console.log(
    '\nYou can now go to ' + chalk.gray('http://' + hostname + ':' + port + '/\n')
  )

  console.log(
    'Enter ' + chalk.cyan('`s`') + ' at any time to create a snapshot of the db\n'
  )

  process.stdin.resume()
  process.stdin.setEncoding('utf8')
  process.stdin.on('data', function (chunk) {
    if (chunk.trim().toLowerCase() === 's') {
      var file = 'db-' + Date.now() + '.json'
      _db.save(object, file)
      console.log('\nSaved snapshot to ' + chalk.cyan(file) + '\n')
    }
  })

  if (filename) {
    var router = jsonServer.router(filename)
  } else {
    var router = jsonServer.router(object)
  }

  var server = jsonServer.create()
  server.use(jsonServer.defaults)
  server.use(router)
  server.listen(port, argv.host)
}
function start ( object , filename ) { var port = process . env . PORT || argv . port var hostname = argv . host === '0.0.0.0' ? 'localhost' : argv . host for ( var prop in object ) { console . log ( chalk . gray ( '  http://' + hostname + ':' + port + '/' ) + chalk . cyan ( prop ) ) } console . log ( '\nYou can now go to ' + chalk . gray ( 'http://' + hostname + ':' + port + '/\n' ) ) console . log ( 'Enter ' + chalk . cyan ( '`s`' ) + ' at any time to create a snapshot of the db\n' ) process . stdin . resume ( ) process . stdin . setEncoding ( 'utf8' ) process . stdin . on ( 'data' , function ( chunk ) { if ( chunk . trim ( ) . toLowerCase ( ) === 's' ) { var file = 'db-' + Date . now ( ) + '.json' _db . save ( object , file ) console . log ( '\nSaved snapshot to ' + chalk . cyan ( file ) + '\n' ) } } ) if ( filename ) { var router = jsonServer . router ( filename ) } else { var router = jsonServer . router ( object ) } var server = jsonServer . create ( ) server . use ( jsonServer . defaults ) server . use ( router ) server . listen ( port , argv . host ) }
Start server function
Start server function