What is Node.js - Node.js Basics [02] - Java Brains

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
okay so what is no js' I'm not gonna leave you with like a textbook definition right I want you to leave this tutorial with an actual understanding of the concept so that you actually get what nodejs is about let's look at the definition on nodejs rargh tells you what no Jace is about right it says no js' there's a JavaScript runtime built on Chrome's v8 JavaScript engine let's parse this thing specifically the first part where it says no J's as a JavaScript runtime that's actually what nodejs says right it's a JavaScript runtime but in order to understand what a JavaScript runtime is you need to really understand the difference between language and runtime what's the difference between a language and a runtime so think about the origins of JavaScript so why was JavaScript created it was created to solve a specific problem and that problem is to achieve some dynamic functionality in the browser before javascript the browser the web browser was something that showed static documents write HTML and CSS are essentially static you load a page you get a certain view you load that page 100 times you get that very same view it's not dynamic it's not interactive so javascript was created to address that need in order to build interactivity in the browser all right so have a browser loading a web page now what you wanted to do the JavaScript is to throw in a file which contains some code or maybe have it be code in the web page itself right throw the JavaScript in and the JavaScript is gonna fire in the dynamic behavior on your web page so you can add things like handlers you can add things like dynamic movement of things in the DOM and all those things so that's the dynamic portion the JavaScript brings in to your web application right or to your web page to kind of make it a web application so this dynamic functionality is enabled by JavaScript this is where javascript was created so what did the creators of JavaScript have to do well they first had to design the language right there was no JavaScript they had to create that language which includes figuring out what the syntax s once they designed the language and they just said okay this have you build applications using this language then they had to build something which actually executes it it's not enough to write a language to design a language and just leave it be you need something that runs it right so they have to build that part as well so when they create a JavaScript they had to design the language and then they also had to enable the browser to be able to take that language write some file with that code written in that language and be able to execute it and actually cause it to run to do the things that it's supposed to do all right so these are the two things that they had to do so the first part which is designing the language is basically designing the syntax so for example if you have like this assignment operator war equals B plus C there is a certain thing that needs to happen when this is encountered so this is the syntax anybody who understands JavaScript syntax can look at this and go yes this is exactly what this is gonna do right so that's the syntax but then just the syntax is not enough like I said we have to have something which executive all right so this is where they created this JavaScript engine right it's a JavaScript engine is something that takes like a dart J's file some file which contains JavaScript syntax and then it executes that it kind of brings it to life it runs the commands in that file this is a JavaScript engine so what the creators of JavaScript did was build a JavaScript engine into the browser so when the browser encounters this javascript file it passes that javascript file to the JavaScript engine and say hey JavaScript engine executes this and then the engine runs that J's father right so this is the difference between the syntax which is the contents of that javascript file and the engine of the runtime which is what takes the contents of the javascript file takes the code and then executes it this runtime cannot really run in isolation it meets some kind of context okay so you can have a runtime which just does assign operators and some and all that stuff but that's not exciting what they wanted to do was to have the trend I'm execute in the browser's context right a developer who's writing javascript code for the browser needs to do something with the page that's loaded on the browser right they need to maybe add a Dom element or more Dom element add some interactivity all that stuff they need to work on the page that is rendered so then somebody is writing javascript in the browser they need access to that context to the page where it's running right so that context is the Dom in the case of a web browser right the document object model which is what represents the page it's a bunch of objects which represents the page so once you have access to the Dom you can manipulate it and thus you can manipulate the page as a result all right so imagine something like this in the browser context you have a JavaScript engine which is sitting in the browser context which contains access to the DOM and then when you pass in a javascript file to the javascript engine your javascript code has access to the context it has access to the Dom it has access to the window object all those things so you can actually manipulate the window you can manipulate the webpage that you're loading no different browsers have different ways in which this is implemented like different browsers obviously have different JavaScript engines you say one browser is slower than the other bells probably because that browser is JavaScript engine isn't optimizes in fast enough and this other browsers JavaScript engine is probably optimized so that's implementation which differs from browser to browser however we're going to take a specific browser and a specific engine for our discussion we're gonna pick the Chrome browser chrome is a popular browser as you might know and the engine the JavaScript engine inside the chrome browser that's called the v8 engine it's the name of the JavaScript engine which kind of powers all the JavaScript execution okay so you can imagine then you load a page in chrome and it loads the page you know they have creates the Dom elements and all that stuff and it encounters a JavaScript file the JavaScript file is executed by the v8 engine which is sitting inside Chrome but then the Chrome browser is giving it the context that's giving it the window it's giving it the document object so you can in your javascript file you can access the window object you can access the document object and then manipulate it okay so this is the setting in which your javascript file would execute in the Chrome browser all right so it's basically delegating the execution to this core v8 engine which is what executes this JavaScript but then it provides the context of the browser and the window now in this particular scenario the context is kind of fixed v8 is always running inside the Chrome browser and it has access to only one context what's the context it's the page that's loaded because Chrome browser can load only webpages so v8 is operating under only one context which is the Dom context so this is where people started thinking okay now what if we take that v8 engine out of the browser and use it somewhere else okay because using only the Dom context is a little bit limiting with the engine running inside the Dom context in a browser you have access to the page that's loaded but can you access say the file system from the v8 engine no you cannot because the browser restricts you from doing that so some smart people thought well why don't we take the p8 engine out of the Chrome browser and have it run on like an operating system just like other programming platforms to get run C or Java or whatever else code which has access to the operating system api's why don't we give dad the context for the v8 engine rather than this fixed Dom context all right so if we were to take that out and put it in this different context we're going to call this the node.js context and have the node.js context provided access to the file system provided access to the network api's provide access to all the other processes in all those things right core operating system context and not restricted only to the Dom context if you were to provide this different context to that same v8 engine now guess what you can write JavaScript code but you can do all those things that you can do with other languages like C or Java right all that matters is the context here if you are taking the engine out of the browser's limited context and giving it all these API is giving it availability to all these different powerful api's well you can do all the stuff that you can do in any other language but you can write JavaScript right so this is what node.js is no js' is this runtime which is actually leveraging this v8 engine that's available in Chrome but then it provides this richer context it provides access to a whole lot of api's including core file system api is process API and all those things that you would typically expect in a normal programming environment and now if you give your Java stop file to this guess what now we can write your JavaScript code to access those different API is right that rich context that node.js provides the v8 engine and then the v8 engine is going to happily run your JavaScript code and say yeah you want me to access the file system I can now do that I'm not shackled by the limitations off when I was living in the chrome browser and I'll have access to all those different api's so it's gonna happily execute your code and you as a developer has access to all those different api's in your JavaScript code right so this ladies and gentlemen is what nodejs is now what's the context here there is a bunch of things that you can access like I mentioned you can have access to the system resources so things like memory filesystem input/output Network and a whole lot more right so this is possible using node.js now with this understanding let's look at the definition again nodejs is a JavaScript runtime built on Chrome's v8 JavaScript engine node.js is this wrapper JavaScript runtime which leverages Chrome's v8 but provides contacts and richer api's so that he can achieve a lot more writing in JavaScript so now that you have this understanding of nodejs let's actually install it on our machines and run it so that you know what it feels like so check out this next tutorial where we do just that you
Info
Channel: Java Brains
Views: 51,152
Rating: undefined out of 5
Keywords: java, javascript, java brains, tutorial, brains, koushik, kaushik, brainbytes, explained, javascript tutorial, learn javascript, javascript tutorial for beginners, javascript programming tutorial, javascript programming, javascript programming for beginners, koushik kothagal, beginner, javascript training, nodejs tutorial, nodejs course, javascript nodejs tutorial, what is node js, what is node.js, node
Id: _RSL3S3Anxg
Channel Id: undefined
Length: 11min 47sec (707 seconds)
Published: Tue Mar 17 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.