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
Last updated: 25th Jan, 2025 Have you ever wondered how to seamlessly integrate the vast…
Hey there! As I venture into building agentic MEAN apps with LangChain.js, I wanted to…
Software-as-a-Service (SaaS) providers have long relied on traditional chatbot solutions like AWS Lex and Google…
Retrieval-Augmented Generation (RAG) is an innovative generative AI method that combines retrieval-based search with large…
The combination of Retrieval-Augmented Generation (RAG) and powerful language models enables the development of sophisticated…
Have you ever wondered how to use OpenAI APIs to create custom chatbots? With advancements…