Following are the key points described later in this article:
var drawTraingle = function() {
console.log("Traingle drawn");
}
var drawCircle = function() {
console.log("Circle drawn");
}
Above code could be saved as draw.js. The file draw.js could be used to represent a module representing functions to draw different shapes. As per this page, module.exports is the object that’s actually returned as the result of a require call.
module.exports = {
drawTraingle: function() {
console.log("Traingle drawn");
},
drawCircle: function() {
console.log("Circle drawn");
}
};
The above code could also be written as following:
var drawTraingle = function() {
console.log("Traingle drawn");
};
var drawCircle = function() {
console.log("Circle drawn");
};
exports.drawTraingle = drawTraingle;
exports.drawCircle = drawCircle;
Following code represents how the above function can be used in other file, say, main.js
var d = require("./draw.js");
d.drawTraingle();
d.drawCircle();
Pay attention to usage of “require” function.
node main.js
It would print following:
Traingle drawn
Circle drawn
When working on a machine learning project, one of the key challenges faced by data…
Last updated: 1st May, 2024 The bias-variance trade-off is a fundamental concept in machine learning…
Last updated: 1st May, 2024 As a data scientist, understanding the nuances of various cost…
Last updated: 1st May, 2024 In this post, you will learn the concepts related to…
Last updated: 26th April, 2024 In this blog post, we will discuss the logistic regression…
Last updated: 22nd April, 2024 As data scientists, we navigate a sea of metrics to…