Skip to content

Instantly share code, notes, and snippets.

@harish2704
Created July 19, 2017 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harish2704/299d520b641ae4fc00c4aa18da1173f8 to your computer and use it in GitHub Desktop.
Save harish2704/299d520b641ae4fc00c4aa18da1173f8 to your computer and use it in GitHub Desktop.
Log promise in Node js repl. This will add a command ".log" which can be used like ".log Promise.resolve(123)" Raw
function logSuccess( a, b, c ){ console.log('Success'); global.uu = arguments; global.aa = a; global.bb = b; global.cc = c; }
function logError( e ){ console.log( 'Error'); global.ee = e; }
function log( promise ){ promise.then(logSuccess).catch(logError); }
function doLog( task ){ var cmd =`log(${task})`; this.outputStream.write(cmd); this.context.vm.runInThisContext(cmd); this.displayPrompt();}
repl.repl.defineCommand('log', doLog);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment