Answers for "What is the syntax to export a function from a module in Node.js"

28

What is the syntax to export a function from a module in Node.js

function foo() {}
function bar() {}

// To export above functions:
module.exports = foo;
module.exports = bar;

// And in the file you want to use these functions,
// import them like this:
const foo = require('./module/path');
const bar = require('./module/path');
Posted by: Guest on January-26-2020
18

how to export module in node js

module.exports ={
 //functions
}
Posted by: Guest on May-30-2020
1

Example: Export a function in Node

function add(a,b){
return a + b;
}

function sub(a,b){
return a - b;
}

function mul(a,b){
return a * b;
}

function div(a,b){
return a / b;
}

exports.add = add
exports.sub = sub
exports.mul = mul
exports.div = div
Posted by: Guest on June-15-2021

Code answers related to "What is the syntax to export a function from a module in Node.js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language