Answers for "nodejs export variable"

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

Example: Export a Variable in Node

var PI = 3.1416
exports.PI = PI;
Posted by: Guest on June-15-2021

Code answers related to "nodejs export variable"

Code answers related to "Javascript"

Browse Popular Code Answers by Language