Print stats when processing multiple records in a looping scenario. Shows you:
- Number of rows.
- Number of errors.
- Records per second.
- Overall elapsed time.
import { stats } from 'print-stats'
const dbStats = stats('myCollection')
const records = await getSomeData()
for (const record of records) {
try {
await someDatabase.write(record)
dbStats.incRows()
} catch (e) {
dbStats.incErrors()
}
dbStats.print()
}
// myCollection: Rows 6,376 | Errors 1 | Rate 14 rec/sec | Elapsed 7m 15.8s