Skip to content

Instantly share code, notes, and snippets.

@swashcap swashcap/cli
Created Feb 15, 2016

What would you like to do?
Node’s Uncaught Exception
#!/usr/bin/env node
'use strict';
const logger = require('../src/utils/logger.js');
const pkg = require('../package.json');
const program = require('commander');
const server = require('../index.js').server;
const url = require('url');
const config = {};
* Error handler for server errors, process `uncaughtException`s and
* process `unhandledRejection`s.
* @param {Error} error
* @param {Promise} [promise]
function errorHandler(error, promise) {
if (typeof promise === 'undefined') {
logger.error('Server error', error);
} else {
logger.error('Server promise rejection', error, promise);
process.on('uncaughtException', errorHandler);
process.on('unhandledRejection', errorHandler);
process.on('exit', function() {'Shutting down server…');
.option('-db, --database', 'Database connection string')
.option('-s, --seed [value]', 'Seed the consortiameta database');
program.on('--help', function() {
console.log(` Databases:
Specify the CouchDB database connection as a URL string:
$ coinstac-server-core --database http://localhost:5984
Pass the '--seed' flag to use the built-in seed documents. You may also pass
in the path to your custom consortiameta JSON file:
$ coinstac-server-core --seed ./path/to/my/docs.json
if (typeof program.seed === 'boolean' || typeof program.seed === 'string') {
config.seed = program.seed;
if (typeof program.database === 'string') {
config.db = {
remote: {
db: url.parse(program.database),
}'Starting server…');
.then(() =>'Server ready'))
'use strict';
module.exports = {
server: function() {
throw new Error('imma error');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.