NodeJs: Core Modules

Core modules comes with NodeJs. Core modules are consumed by using require & specifing the file name directly. Below are few important core modules in nodejs.

1. Path Module: Use require(‘path’) to load this module. It provides useful string transformations when working with file system

normalize(str): fixes slash based on os & takes care of . & ..

join(str1, str2, str3..): combines the provided strings and gives the final path

dirname, basename & extname: gives directory name, filename and file extension of the file provided

2. fs Module: fs module deals with renaming, deleting, reading and writing files

fs.writeFileSync(filename, content to write)

fs.readFileSync(filename to read)

3. os Module: os module provides data related to operating system

os.totalmem() – info related to total memory

os.freemem() – info related to free memory

os.cpus().length – total no of cpu’s

4. util Module:contains general purpose functions

util.log – To log information

util.format – similar to printf in c/c++ with %s for string and %d for numbers

and various functions like util.isArray, util.isDate, util.isError etc..


One thought on “NodeJs: Core Modules

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s