Getting Started With Node – Course

How to Create Node Modules

You can create your own node module. All you need to do is create a function and export it for the reusability. For example, consider this code which can acts as a node module.

exports.currentTime = function () {
  return Date();
};

You can reuse this module in your code like this:

var dt = require('./mymodule'); // assuming the file name is mymodule.js

console.log('current time is '+dt.currentTime());

This is really simple example. However, this gives an idea about how to create node modules.

If you are interested in more detailed information, visit this tutorial.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.