Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 79 lines (63 sloc) 1.23 KB
#!/usr/bin/env node
/**
* Module dependencies.
*/
try {
var nedis = require('nedis');
} catch (err) {
var nedis = require('../');
}
/**
* Arguments.
*/
var args = process.argv.slice(2);
/**
* Options.
*/
var options = {};
/**
* Usage information.
*/
var usage = [
''
, ' Usage: nedis-server [options]'
, ''
, ' Options:'
, ''
, ' -p, --port <n> specify port number'
, ' -d, --debug output debug information'
, ' -h, --help output help information'
, ''
].join('\n');
/**
* Require argument for `flag`.
*
* @param {String} flag
* @return {String}
*/
function required(flag) {
if (args.length) return args.shift();
console.error('\n \033[31m%s requires an argument\033[0m\n', flag);
process.exit(1);
}
// parse arguments
while (args.length) {
switch (args.shift()) {
case '-h':
case '--help':
console.log(usage);
process.exit(0);
break;
case '-d':
case '--debug':
options.debug = true;
break;
case '-p':
case '--port':
options.port = required('--port');
break;
}
}
// Start server
var server = nedis.createServer(options).listen(options.port);
console.log('Nedis started on port %d', server.address().port);