Answers for "use import export in nodejs"

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
-1

node package.json type module

node --experimental-modules app.js
Posted by: Guest on July-29-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language