Q:

module.exports multiple functions

//Inside lib file declare functions
const animalName = (name) => {
	console.log(name)
}
const animalSound = (sound) => {
	console.log(sound)
}
//Export these both as JSON
module.exports = {animalName, animalSound}

//Navigate to file you want to use them and import
const animalLib = require('./location_of_file.js')

//To access the function
animalLib.animalName("zebra")
2
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');

15
module.exports ={
 //functions
}
5
module.exports = function(firstParam) { console.log("You did it"); },
module.exports = function(secondParam) { console.log("Yes you did it"); }, 
// This may contain more functions
0

New to Communities?

Join the community