thenlog

js promise .then() calls logger for node and browser

Usage no npm install needed!

<script type="module">
  import thenlog from 'https://cdn.skypack.dev/thenlog';
</script>

README

.then log

The js-promise-.then()-calls logger for both node.js and browser.

require('thenlog');

Promise.resolve(0)
  .thenlog(v=>v + 1)
  .thenlog(v=>v * 2)
  .thenlog(v=>Math.pow(v, 4))
  .then(v => v)
  .thenlog(v=>v / 0)
  .thenlog(v => {})
  .then(v => 'foobar');

Browser / Node.js

Story en

Promise chains debugging is not too convenient. You have to replace code shorthands (e.g. .then(_.union)) by long statements with a console.log instructions.

You have to see many 3th-party call-chains in the browser inspector's debugger in async mode. And debugger injection in node.js for async code debugging using node debug is not convenient way again.

Story ru

Дебажить промисы не очень удобно. То и дело приходится разорять изящные конструкции вида .then(_.union), внедряя туда console.log.

В дебаггере браузера часто приходится смотреть на полотна 3th-party кода. А в node.js с помощью node debug чтобы отлаживать асинхронщину приходится внедрять тут и там debugger, что очень неудобно, см. выше.