node date function

Creating Node.js Modules

Modules are javascript libraries that can be used in developing an application.They are set of functions.

Types of Modules

1.Built in modules-these are node.js modules that can be used without installing them.Example of these modules are:-

  • http-makes node.js act like http server.
  • https-makes node.js act like https server etc.

      How to include built in modules

To use a built-in module we use require () function adding the module name.

Example: var http=require(‘http’);

After adding above code now your application can access http module and be able to createServer


2.Own modules-Node.js developers can create their own modules and use them.


      Code to create a module that returns date and time


The exports keyword makes the module methods and properties available outside module file.

Save the above code as “firstmodule.js”

       Including your own modules

Example code.

Save above code as ‘demo_first_module.js’. Run the code by typing

C:\Users\Your Name>node demo_first_module.js




Code var date=require(‘./firstmodule’);  is used to include the module


We use  ‘ ./ ’ meaning that the module is contained in the same folder as the node.js file.


node date function