Answers for "exporting module function js"

31

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
0

exporting functions

//myfile.js
export function fn1() {...} 
export function fn2() {...} 
import * as MyFn from blabla
                       myFn.fn1();
Posted by: Guest on April-30-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language