Node.js
So we now know why we need a backend in order to create a web application.
But which technology are we going to use to create it?
Well, we’ve actually got quite a few options. You could use Java, Ruby on Rails, PHP, ASP.Net, Node.js, Python, and a whole load more.
But why Node.js?
Well, the most important thing is that we already know Javascript, and Node.js allows us to create a backend using Javascript. So we can use one language and we don’t have to spend a lot of extra time learning about yet another language and all of its intricacies.
We already know how to use Javascript. Now, in addition to that, Node is also superfast and will allow us to create really scalable and fast running web sites. And we’re not the only ones choosing Node.
We’re in really good company here.
Web sites such as eBay, Uber, Trello, Twitter, Netflix, all use Node.js in their backend, and more and more companies are joining their ranks and starting to use Node.
Now in the last few years, if you’ve been to any technical conferences, you’ll hear Node Node Node Node Node all day long, and there’s a lot of people who are super excited about this technology. And in the coming lessons, you’re going to see exactly why and how awesome it can be. So we’ve talked about why we want to use Node. But what exactly does it do anyway?
Well currently, on our web sites, we’ve written Javascript code, and we’ve been able to execute it inside our browser.
Now that’s really really important. But up until now, that Javascript code has been locked behind bars and kept inside the browser, so it’s only been able to interact with the browser, request information from the browser, add event listeners to components in the browser, but we’ve not been able to write Javascript code for our web site that’s able to go beyond the boundaries of the browser.
For example, our code isn’t able to reach out of the browser into the user’s computer and get access to, for example, the file system, or the networking processes. And there’s a very good reason for that.
You don’t want to load up a web site that’s written by some random person with a whole load of Javascript on it that’s got malicious code: bugs, viruses, hackers who are trying to tap into your local file system.
It’d be really really dangerous if they could download or look into your local files,
right?
But there are some situations where, for example, if you were to build a desktop application, then you do need to access the file system in order to load up those code files that the user is going to edit, right?
And in these situations, you need to be able to access the file system or listen to the network request.
Basically, you need to be able to write code that can interact directly with the computer, independent of the browser. And that’s exactly what Node.js allows us to do.
It allows us to take Javascript out of the browser and it liberates it, allowing it to interact directly with the hardware of a computer.
So we can now use Javascript inside our web site in order to give it functionality and behaviour, for example implementing animations, or dropdown menus. But Node.js allows us to use Javascript to interact directly with the hardware of the computer. So we can use it, for example, to create a desktop application.
And in fact, Atom, the code editor that we’ve been using, is based on Node.js.
So now, with Node.js, you can write Javascript code not just in the browser to affect the behaviour of your web sites, but also to write full applications that work on your computer.
Well, we can run Node.js on our own computer, but we could also use Node.js to run Javascript code on somebody else’s computer, or rather, a server. And what that means is that a user could log on to Google and put in a query, and your browser will make a request to Google servers, and on those servers, we can actually execute Javascript code to process their request.
And after that’s done, we can send back the result to the user, or to the client, and simply get their web browser to display the information, and all of that heavy lifting, the code execution, happens behind the scenes, on the server, rather than on the client-side, and that will make your web site a lot more capable.