Skip to content

litmit/console-sync

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

console-sync

Node.js synchronous console

Installation

npm install console-sync

Usage

require("console-sync"); // patch console object

console.log("now this call do synchronous output");

Overview

Because console is asynchronous the following sample.js

for(var i=0; ;++i)
{
   console.log("Value of i=%d",i);
}

will consume all available memory and crash after several minutes of execution with message:

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

See this issue for details.

For Node.js v4.x it was workaround: redirect a output to a file.

node sample.js > sample.out

This works perfectly and allows to output a large amount of information using console.log() in a synchronous application without any unneeded asynchronous complexity.

But this workaround not work at all for Node.js v6.x.

I publish issue with request for fix this behavior.

But meanwhile possible to patch the console module using this package.

require("console-sync"); replace log,info,warn,error and dir methods with synchronous analogs.

About

Node.js synchronous console

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published