JavaScript

NodeJS - Creating Module

Many times we uses modules in nodejs applications which comes from different package added in package.json file. This allows us to organize the code and to create reusable components.

Here are simple steps to create your own custom module.

Create a module file mymodule.js

exports.myServerTime = function () {
  return "Today is "+Date();
};

In the above code, you would notice a keyword "exports" which make properties and menthods of this module outside of this module file.

JavaScript - How does Inheritance work in Javascript

In JavaScript, you can use Object Oriented Design concept and one of them is inheritance. In JavaScript, you can create child object from parent object and can override some properties if you want. Here is the example.

We have course Object which has properties name, duration and location with their respective values.

course = {name:'CKD', duration:'3 months', location:'india'}

Now, below we are creating another object with course object but would override duration property.

Tags