a blog for those who code

Friday, 11 July 2014

Utilities Module in Nodejs

In this post we will show whats the use of Utilities Module in Nodejs. A lot of methods in this Utilities Module comes handy in a day to day application.

You can include the Utilities module in your application with
> var util = require('util');

We can use Utilities for :

util.isArray : To check if an object is an Array
util.isRegExp : To check if an object is a Regular Expression
util.format : To format a string
util.pump : To pump data from a readable stream to writable stream.
util.inspect : To get a string representation of an object.

In util.inspect the first argument is the object itself whose string represent you want which is a required one. The second optional argument is whether you want to display the non-enumerable properties, the third optional argument is the number of times the object is recursed, and forth argument which is also optional, is whether to style the output in ANSI colors.

> var util = require('util');
> console.log(util.inspect(object,true,null,true));

Please Like and Share the Blog, if you find it interesting and helpful.

No comments:

Post a Comment

Contact Us

Name

Email *

Message *

Sponsers

Best Hosting Plans

CC License