Hey, guys, in this lesson we're going to be learning all about Node.js what it is and why we're choosing 1
to use it. 2
So we know that we can use lots of different languages to write the backend of our web application. 3
And we've also seen that depending on the language we want to choose, we can also find a compatible 4
framework to go along with it. 5
Now why would you need a framework anyways? 6
Why can't you just write all the code from scratch using the chosen programming language and create 7
your web server that way? 8
Well, in some ways, a framework is a bit like mayonnaise. 9
You know me, 10
I love my food analogies. 11
So let's say you're a chef and you wanted to make some sort of recipe and a great recipe using mayonnaise, 12
by the way, is chocolate cake. 13
It sounds really weird, but Google it and try it, 14
it actually tastes really, really delicious. 15
Anyways, now let's say you're hungry at lunch and you wanted to make a Tuna Mayo sandwich. 16
You could, of course, make your own mayonnaise, but alternatively, you could also just use store 17
bought mayonnaise, 18
and in that way, the mayonnaise is kind of like a framework. 19
You need all those components, the egg and the vinegar in order to create the end product, which is 20
your web app, or in this case our Tuna Mayo sandwich. 21
And you could write all of your own code, or because this is such a commonly used functionality or in 22
this case a commonly used condiment, you could also just get the mayonnaise framework. 23
And in that way, a Web-framework provides pre-built components and structures that can be used to build 24
an application without the need for us to write every single line of code from scratch. 25
But when we think about Node, it's actually not quite a framework. 26
It's, "An asynchronous event-driven JavaScript runtime, 27
Node.js is designed to build scalable network applications." And this is according to Node.js themselves. 28
So pretty much straight from the horse's mouth. 29
So it can't get more accurate than that. 30
Now what does it mean? 31
Let's break it down. 32
It's a JavaScript runtime. 33
Now what is a runtime environment? 34
Now the important thing to remember here is that when JavaScript was first created, it was designed 35
to run in the browser. 36
This means that it was impossible to use JavaScript to write any kind of program that's not a website, 37
but Node uses the V8 engine, not this eight cylinder V8 engine, but this V8 engine which comes from 38
Chromium. 39
It's written in C and C++. 40
It's blazingly fast and it powers the Chrome browser. 41
So we know that we can write JavaScript code to run in the browser and to provide functionality to our 42
websites, 43
but in many ways, the JavaScript code that we have is locked in the browser land jail. 44
And when Node came along it effectively liberated the JavaScript out of browser land and gave it the 45
freedom to allow us to use it to write any sort of application, desktop or server side. 46
Now that Node provides us with this JavaScript runtime so that we can run JavaScript on a machine such 47
as your own local computer, 48
then it means that we can use JavaScript to accomplish pretty much anything that other popular server 49
side languages like Ruby, PHP, C-sharp, Python can do, but maintaining our full JavaScript stack 50
from frontend to backend. 51
Now what about the other part of this sentence? 52
It's asynchronous and event-driven. 53
What does this mean? 54
Well, essentially asynchronous means that your JavaScript code doesn't have to do everything sequentially. 55
If we think back to the scripts that we've written before, our code kind of runs from top to bottom 56
and we can have some functions, but essentially everything is going to happen from beginning to end 57
in a synchronous way. 58
Now what does asynchronous mean? 59
Well, let's say that you went on to Amazon, not that kind of Amazon, this Amazon, and you ordered 60
yourself something. 61
Now, if this process was synchronous, then it means that you would have to sit there and wait until 62
your parcel gets delivered and you can't do anything else in the meantime. 63
That's what it means to run synchronous code such as our previous scripts written in JavaScript. 64
It's effectively tying up the resources until some sort of event resolves, which in this case is the 65
delivery of your Amazon parcel. 66
Can you imagine a world where you had to wait for your Amazon 67
parcel and you just had to stand at the door and do nothing else after you've ordered it. 68
Now, I don't know what Amazon Prime is like where you live, but where I live, it takes a long time 69
to get one of these parcels and it would be terrible if this process was synchronous. 70
Now, Node, on the other hand, is asynchronous and it's event driven, so it means that you can initiate 71
this order and instead of having to wait for it, it can free up the resources 72
and only when the event of the parcel being delivered does it then continue to run the next bits of 73
code. 74
So effectively, we can parcel up these bits of code into an event so that we know that our code can be 75
triggered when this event happens. 76
In summary, the reason why we need Node is because it allows us to build an application often on a 77
computer using JavaScript. 78
And as we saw earlier, the application is a key aspect of our backend. 79
Now that application is going to be running on our server and that server, if you remember, is just 80
a computer, but it's not a browser and Node.js is what allows us to happen. 81
Now, as we saw earlier, there are many, many different choices in terms of languages or technologies 82
that we could use for the backend. 83
So why are we choosing Node? 84
Well, the reason is because if we use Node, which is one of the most popular choices as of today, 85
then it means that our frontend could be written in JavaScript plus HTML and CSS of course, but our 86
backend could also be written in JavaScript. 87
So effectively, that allows us to use JavaScript everywhere inside our web application and this allows 88
us to use one language to rule them all. 89
So the key benefits of Node.js are the fact that it allows us to use JavaScript across the entire stack, 90
which means that developers are using a language they're already familiar with, and it makes it easy 91
for them to transition from frontend to backend developer. 92
And if you're writing a project yourself, then you only really need to be familiar with one language 93
and you can share your code between your client and server side. 94
In addition, Node.js allows for easy Scaling of applications, making it really good for large-scale 95
professional projects. 96
It's fast and it's Non-blocking because of this asynchronous event-driven nature of Node.js, it can 97
be really fast and really efficient, 98
instead of having to wait for things to happen or blocking the resources. 99
Finally, it's got a huge ecosystem. 100
It's got a really vibrant community and people have contributed thousands of open-source modules and 101
packages to the Node Package Manager, which allows us to easily add functionality to our own applications. 102
But also it means that there's a lot of resources out there in terms of documentation, 103
tutorials, help, people on StackOverflow who can answer your questions 104
and plus we're not the only people choosing it. 105
Everything from LinkedIn to Twitter to Netflix is built on top of Node.js and even NASA uses Node.js. 106
I recently came across this report about how NASA started using Node.js in order to keep their astronauts 107
safe and make their data accessible. 108
So if it's good enough for NASA, it's probably good enough for our project. 109
Now, I don't think you needed any more convincing why 110
we are choosing the best possible path, but every single time I give a talk on Node.js, people always 111
ask me, "Why don't we use a C-sharp?" 112
"Why don't we use Python?" Or, "Why don't we use PHP?" 113
People are particularly obsessed with PHP for some reason and as we saw already in the last video, 114
Node is just dominant. 115
It's the thing that you're going to need to know if you want to get a job. 116
And it's the thing that most people look for as a key skill in a web developer. 117
And we're trying to become web developers, right? 118
If you want to learn about Python and Python based backends, which are really great, if you're working 119
with machine learning projects or anything to do with machine learning and AI, then be sure to check 120
out my Python course where we cover the use of Flask in the backend and using Python. 121
Now one final piece of interesting stat from GitHub which looks at the programming languages of code 122
that is committed across the entirety of GitHub, 123
and you can see that JavaScript is just still king. 124
Python is growing in popularity and for example, PHP 125
for some reason I always get asked 126
about this, 127
"Why are you not teaching PHP?" 128
Well, it's because it's not really a very good idea to teach you PHP at this point, 129
and in fact, if you see any Web Development Bootcamp that's teaching PHP or Ruby on Rails, then you 130
should probably be asking yourself if they have updated their curriculum within the last ten years. 131
There you have it. 132
You should now understand what Node.js is, what it allows us to accomplish, and why we're choosing 133
it to build our backend. 134
In the next lesson, I'm going to be showing you how to install Node.js on your local computer so we 135
can get started building applications using Node. 136
So for all of that and more, I'll see you there.