Node JS Tutorial for Beginners #7 - Module Patterns

preview_player
Показать описание


----- COURSE LINKS:

---------------------------------------------------------------------------------------------
You can find more front-end development tutorials on CSS, HTML, JavaScript, jQuery, WordPress & more on the channel homepage...

========== JavaScript for Beginners Playlist ==========

============ CSS for Beginners Playlist =============

============== The Net Ninja =====================

================== Social Links ==================

Рекомендации по теме
Комментарии
Автор

There is an easier way to do this in ES6. In stuff.js you can use Object Literal Shorthand:
module.exports = {counter, adder, pi} // if the property and value of an object is the same you can simply write the property name only (In ES6 only).
In app.js you can use Destructuring:
var {counter, adder, pi} = require('./stuff') // This makes it easier because you won't have to write stuff.Name every time you get anything from the module (Also in ES6 only).

KareemMFouad-dtzr
Автор

I hope you never stop making tutorials. Ever. I mean seriously, after all is gone and we're in the middle of an apocalypse selling out our own grandma for a can of beans. I would still like to think you're out there in a cave somewhere with great wifi uploading more tutorials.

asmayoutube
Автор

In ES6, there's a shorter way to initialize the module.exports object :

module.exports = {
counter,
adder,
pi
}

This works only when both the property and the value names are identical. So, instead of saying -> counter: counter in the object twice, we only say -> counter.

adityakeri
Автор

Highly recommend following along in your text editor at home. I previously watched all of these without coding and it felt like I forgot it as soon as I finished watching. When you do it yourself, it feels more imprinted in the brain.

OperationAndrew.
Автор

These tutorials are excellent. I have watched so many tutorials but none has as clear explanations as yours. I am not going to skip ads on your videos as a thank you!

maidenfreek
Автор

You can also do things like this:


module.exports = {
counter(arr) {
return `There are ${arr.length} elements in this array!`
},
adder(a, b) {
return `The sum of the two numbers is ${a + b}.`
},
pi: 3.145
}


Thank you for a good tutorial series :)

johnyonardpauly
Автор

Man you are just too good. You have a knack for simplifying hard concepts. thank you so much man.

nicholasking
Автор

the size chuck of each tutorial is very well organised, thanks for the great series, super easy to follow, barely even have to pause

auchucknorris
Автор

I was quite perplexed after the previous video. But this one cleared all my doubts. Thanks a ton

athulmurali
Автор

Thank you for great tutorials. I keep coming back for reference.

Just want to add another way of exporting:

// **** //
var stuff = { };

stuff.counter = function ( arr ){
// inside logic
}

stuff.adder = function ( a, b ) {
// adder logic
}

stuff.pi = 3.14;

module.exports = stuff;

koushikut
Автор

Hey man you are honestly a great teacher, came here for NodeJS but realized this guy might be able to teach me JS better than others. So yeah I am gonna stick around a little longer. I already know where I am headed to after finishing this series.
Thanks Mate

slmshady
Автор

this series has made so many things clearer that I had no idea about because they were so confusing to me previously. Top work!

JoshBowman
Автор

the way you explain things is just amazing. thanks for sharing your knowledge.

yohrocks
Автор

I like the object way of exporting things ...AWESOME, BEST TUTORIAL ON THE PLANET

mshimanshu
Автор

Your videos explicitly answer questions I have in previous videos and it blows my mind

boring-username
Автор

You break things down in way that anyone can learn, Thanks, and keep up the good work.

suemendez
Автор

Thank you. JS Modules always got me confused because of the way I was used to thinking about JS and you made it so so simple.

morezco
Автор

Doing great job Ninja.. Best tutorial so far on youtube for beginners.

kunalpuri
Автор

Thank you for the tutorial, it is a true jewel comparing to others. Not only you hit right into the topic with every detail but you could also be a great radio speaker! I could listen to you for hours ;)

wounky
Автор

you are a verygood teacher! brief yet complete, discussing just what needs to be discussed. thank you!

jeteloriaga