Explain module.exports in Node Js ?

devquora
devquora

Posted On: Apr 08, 2024

 

The method or variable defined in modules cannot be directly accessible by the outer world, that means you cannot call a module member from the external file. In order to access module member, we need to export the functions or variables of modules using module.exports method.

Syntax and usage:

// greet.js
var greet=function(){
console.log("hello World");
}
module.exports=greet;

//In app.js

var greet=require('./greet.js');

greet();

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    Node JS Interview Questions

    What is Node js ?

    Node Js is one of the most popular and powerful server technologies today. It allows you built the entire website only..

    Node JS Interview Questions

    Explain CLI in Node.js?

    CLI stands for Command Line Interface. It is a utility or program on your computer where users type commands to perform..

    Node JS Interview Questions

    In which Language Node Js is written ?

    Node js is written in C, C++,JavaScript.It uses Google’s open source V8 Javascript Engine to convert Javascript code..