Node.js Crash Course Tutorial #1 - Introduction & Setup

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey gang and welcome to your very first step in becoming a node ninja a rather than gang now I do already have a node tutorial on this channel but I wanted to update it because now that's about four or five years old so I wanted to do a quick refresh a nice new node tutorial because in the future I'm going to create some more advanced node tutorials as well and then I can direct people to this more recent playlist to learn the basics first of all okay there so first things first what is node j/s well as developers when we're creating websites we normally talk about code on either the front end inside browser or back end code or server-side code which is the code which runs on a server now javascript is normally confined to run in a browser in the past on the front end and we'd use it to do things like add interactivity to a web page like click events or things like that now we never used to be able to run JavaScript directly on a computer or server but node allows us to run JavaScript on the server side as well or even directly on computers now before you explain any more about that first of all I want to talk a little bit about how computers actually understand code so computers really only understand machine code but that is really complex to write and a read it's like binary like this so something called assembly language is built on top of that which is a bit easier to read and write which is then assembled down into machine code so the computer can still understand it but this right here this assembler language is still overly complex to read and write so built on top of that we have programming languages like C++ which are abstracted a lot away from assembly code and they're much easier to read and write so ultimately this C++ code is then compiled down to machine code so therefore we can write C++ code on a computer and a computer will understand it because it's being compiled down to machine code now javascript is a language which is abstracted even more away from machine code than C++ to make programming easier still but computers cannot directly understand JavaScript or compile it down to machine code so we cannot directly run JavaScript on a computer right but it can run inside a browser so how does that work well running inside browsers is an engine called the v8 engine and the v8 engine is written in C++ by Google and it compiles JavaScript into machine code at runtime so bypassing JavaScript code through this v8 engine in the browser the computer can then understand JavaScript within the context of that browser however it cannot run JavaScript outside the browser because there is no v8 engine compiling it down outside the browser it's confined to the browser only but that is where node comes into play so node.js is a program also written in C++ and that wraps the v8 engine so this v8 engine that's in browsers also lives inside node as well now because node is written in C++ it can run directly on our computer so by installing and running node on our computer it can take our JavaScript it can run it through the v8 compiler that it has inside it and it compiles our JavaScript into machine code so that in essence we can now run JavaScript directly on a computer or server and not just in a browser but node is more than just a wrapper for the v8 engine it also hooks into the v8 engines and more functionality to JavaScript so that when we are using nodes a compile and run JavaScript we can use all of this extra functionality in our JavaScript code and that kind of functionality includes things like the ability to read and write files on a computer or to connect to a database the ability to act as a server for content these are all the kind of things you'd expect a server-side language to do and now we can do them with JavaScript running through node now remember javascript was originally made for the brow to add interactivity and not to run directly on computers or service so normally it can't do all of this stuff but with the help of node it can but on the flip side since we're now using node to run JavaScript outside the browser we lose access to JavaScript features such as the document object model we can't interact with HTML elements anymore but we don't really need to do that when we're running JavaScript on a server and acting as a back-end to our website right so just going back to computers and machine code node now plugs into the top of this stack with the v8 engine so that now we can write JavaScript code on a computer which is then compiled down into machine code forests so that computers can now understand JavaScript and that is freaking awesome so then now we've got a bird's-eye view of what node actually does for us what would we actually use it for well the role of node in a website is basically to run JavaScript on the back end or server side and then we're going to be handling requests coming in from a browser so for example a user might visit your website in a browser now that browser is going to make a request to the server the node server is going to run some kind of JavaScript you'll react to the request and it might communicate maybe with a database or files on the server then it's going to formulate some kind of response and send it right back to the browser now that response could be an HTML page with dynamic data embedded inside it or maybe some CSS and image files etc so basically the note server is running JavaScript on the back end to do all of this so using node in a website is pretty much an alternative now to or the server-side languages like Python Ruby PHP etc but the rad benefits of using node over the others first of all if you're already familiar with JavaScript then there's absolutely no need to learn a new server-side language because node is going to be taking javascript and compiling it down so we can use the same language on the front end and the back end and to that end we can also share cold for front end and the back end since they both use JavaScript it's very popular and it's got a massive massive community around it so there's always help if you need it and there's also a huge amount of third-party packages and tools to help with web development and we're going to see some of those as we go through this course I rather than so in this course we're gonna go from the absolute beginning and to begin with I'm going to show you how to install node and use it to run JavaScript on your computer or in a server then we're going to see how to use know to read and write files on your computer we'll also see how to create a server and then make a website using node by listing for and responding to HTTP requests then we're going to dive right into third party packages in particular Express to create an express up and that is a very very easy way and a very popular way to build node websites then we're going to introduce databases in particular MongoDB which is a no sequel database and we're going to use that to store data and then create dynamic web pages and to that end as well we will be using template engines ejs in particular to inject dynamic content into our HTML templates which we can then send back to the browser finally we're going to put everything together that we learn to make a node powered website project so this is the little project we're going to create it's a very simple blog website where we can list all of the current blogs we can click on one to see more information we can also go to add a new blog and I'll just call this one Mario Party and add in some ninja tips as you do like so and then click on submit and we can see that new blog at the top over here we can also delete blogs by clicking on this little Delete icon right here and we have an about page as well which every block needs so this is the project we're going to be creating using node Express and also MongoDB as the database as well throughout this series now before we start I want to make one thing crystal clear this is not a beginner Java Script course and you should already know the foundations of the JavaScript language things like functions how asynchronous code works all that kind of just and ideal it you should also know a little bit about HTML and CSS too since at the end of the day we are making a website and there will be HTML and CSS involve now I've got courses on both of these things on this channel and on udemy I've got a modern JavaScript course and also an HTML and the CSS crash course as well so the links to both of these are going to be a highlight down below a rather than gang so the first step in all this is to install node on your computer now it might be that you already have node installed on your computer but you're just unaware of it so in order to check that open up a terminal I'm going to use command prompt by typing CMD and pressing enter and then in here type node space hyphen V and if you have node installed it should give you back a version number you can see mine is version 14 point 1.0 now if you don't get a version number it means you don't have node installed and you're gonna have to go ahead and install it likewise you might get a different number a smaller number which means you have an older version of node in which case you might want to update as well so in order to do that to install it or update it go to node.js org this link will be down below and then click on this button right here to install the latest version that's going to download an installer run that when it's done and the install wizard will install node on your computer for you it only takes a couple of minutes now once you've done that I would suggest closing your terminal opening it up again and typing in node - V just to make sure you get a version number and it's installed correctly so now you have node installed on your computer we can use it to run JavaScript directly on our computer and we could even do that directly inside this terminal so to do that I'm gonna type node and then enter and that starts the node process and right now we see a blinking cursor and that's asking us to basically type some JavaScript to run through node so now I could write something like 5 plus 5 press ENTER and we get back 10 that's valid JavaScript right and we could write any JavaScript code that we want to write here so I could say var name is equal to Mario and then type name and we get back and Mario so any kind of valid JavaScript we can write inside this terminal but ideally we don't want to write code in a terminal all the time it's going to be really tough to create a website this way so instead we're going to need a good text editor to work in now I'm going to be using vs code of Visual Studio code which is a great free text editor and you can get it from code dot visual studio comm and click on this download button right here for Mac or for Windows but you don't have to use this you can use your own favorite like sublime or atom if you prefer but at the minute I would recommend this one it's a really nice text editor so anyway once you have your text editor installed open it up and maybe start a new project folder in that text editor I'm actually going to do that from the command line over here so let me exit this process by clicking ctrl C twice and that exits out of the node process then I'm going to navigate to a folder where I want to create my new project so I'm going to say CD which stands for change directory to dive into a folder called documents that I have on my computer then CD again to go into another folder I created called totes and then right here I'm going to create a new directory by saying mkdir that stands for make directory and I'm going to call this node - crash - course and then I'm going to see the into that so see the node - crash - course and then I'm going to open up this particular directory inside of the S code now to open that up from the command line in vs code I can say code dot and that means open up visual studio code in the current directory alright so press ENTER and that should hopefully open up visual studio code in this project directory we can see that right here in node crash course ok so then now we have our text editor open let's just give this a whirl what I'm gonna do is create a new file over here and I'm gonna call this test dot J s and inside you I'm just gonna write some basic JavaScript code so I'm going to say Const and then we'll say name is equal to Mario right and all I'm gonna do is console dot log name so I've got a JavaScript file now on my computer how do I run this JavaScript file well I can do that through the terminal so I'm going to go to terminal at the top and then go to new terminal and make sure you're in the correct directory where the file exists where you made that file and then type node and then the file name so in our case test now you don't need to add the JavaScript extension because it knows we're going to run a JavaScript file so I can just say node test which is the name of the file press ENTER and it runs that file for us on our computer and we actually see down here in the terminal which is acting as the console for us this name Mario okay so it run the file it logged this to the terminal or the console down here so let me try this again I'm going to change this to something else like not your paw but Yoshi and save that now I have to run this file again for it to work so down here I can just press up to do the latest command I wrote and press ENTER again node test and now we can see Yoshi right here so we could write any JavaScript inside this file then run it and if we're logging things to the console we're gonna see them down here inside the terminal and that's how easy it is to run a javascript file on our computer using node this is not being run inside a browser anywhere now it's being run directly on our computer now finally going i've created course files for every single lesson in this tutorial series and they're all found on this give repo right here node crash course now don't worry if you don't know how to use git or github or anything like that you don't really need to know how to to see the code or down load the code I'll leave this link down below but essentially each lesson in this series is going to have its own branch in this github repo so we can see the branches right here and if you want to see the code for lesson 4 for example you could go to the lesson for branch and you're gonna see all of the code right here and all of the different files now if you want to download this you can go to close or download if you're familiar with github and get you can clone the repo to your local machine or if you want to download a zip file with all of this code in you can do by clicking download zip or right here [Music]
Info
Channel: The Net Ninja
Views: 295,809
Rating: undefined out of 5
Keywords: node.js, node, node js, node.js tutorial, node tutorial, node js tutorial, node crash course, node.js crash couse, node js crash course, crash course, tutorial, install node js, install, node.js introduction, what is node.js, what is node js, what is node, node vs deno
Id: zb3Qk8SG5Ms
Channel Id: undefined
Length: 16min 36sec (996 seconds)
Published: Mon Jun 15 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.