Answers for "node module export multiple functions"

7

node module export 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")
Posted by: Guest on July-24-2020
2

js export multiple functions

function foo() { console.log('foo') }
function bar() { console.log('bar') }
function baz() { foo(); bar() }

export default {foo, bar, baz}
Posted by: Guest on September-25-2020
-2

module.exports multiple functions

module.exports = function(firstParam) { console.log("You did it"); },
module.exports = function(secondParam) { console.log("Yes you did it"); }, 
// This may contain more functions
Posted by: Guest on September-20-2020

Code answers related to "node module export multiple functions"

Code answers related to "Javascript"

Browse Popular Code Answers by Language