Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMezzo Forte
1,877 Pointshow to access more then one function
Noticed that the getProfile was set to the get with:
module.exports.get = getProfile;
and called on the app.js side with:
const profile = require('./profile.js');
const users = process.argv.slice(2);
users.forEach(profile.get);
Say I have more then one function in the profile.js module. How would I access that as well if I could only call profile.get. and profile.get has already been assigned to getProfile.
Thank you
1 Answer
Tim Gavlick
11,725 PointsIt also helps to think of module.exports
as an object you're returning from the module. As such, if you have more than one export:
module.exports.get = getProfile;
module.exports.something = something;
You might consider rewriting like:
module.exports = {
get: getProfile,
something: something
}
Kenneth Kim
3,795 PointsTim, so you mean to say that the exports can be formatted to a JSON Object? Afterwards are there any steps to do? Let say for example I want to export 3 methods
module.exports = {
get: getName,
get: getAge,
get: getAddress
}
//module.start export() or something ? or the above code is enough? Thanks. Also by doing export, does it mean that all exported functions are visible to all other JS files?
Mezzo Forte
1,877 PointsMezzo Forte
1,877 PointsNevermind after proceeding to the Questions after the video it made sense? Though I would readly love clarification. The:
the get can be changed. I've tried replacing it with say, getProfile, and other words and it worked fine after accessing it on the app.js side. The get is a property being created then accessed in app.js using the below: