DEV Community

Cover image for Day 7 - More Modules - Learning Node JS In 30 Days [Mini series]
Muhammad Ali (Nerdjfpb)
Muhammad Ali (Nerdjfpb)

Posted on • Edited on • Originally published at blog.nerdjfpb.com

Day 7 - More Modules - Learning Node JS In 30 Days [Mini series]

Today we’re going to learn about some more about module

We are using files as last post.

Now it can happens that in our song folder there are two different functions.

Alt Text

Now how to send this both module, as per we know from last posts we can’t send both functions using this module.exports

Alt Text

Adding module.exports.VARIABLE_NAME we can send it to other file

Alt Text

By using Song.VARIABLE_NAME what we’ve send from song.js file we can call the functions

Alt Text

This is not all, there are some others way you can do it to. What if you have 100 functions in the same file are you going to write one by one ?

Now we can just use module.exports as a object ! Example –

Alt Text

app.js will be the same and if we run it now then same result

Alt Text

now we can modify code a bit. When the name are same in es6 version we can write just once.

Alt Text

So, do you feel you know a bit about module now ?

You can see the graphical version here

Originally it published on nerdjfpbblog. You can connect with me in twitter or linkedin !

Top comments (0)