What is Node.js Exactly? – a beginners introduction to Nodejs
Video Title: What is Node.js Exactly? – a beginners introduction to Nodejs
Hey there so I’ve got a lot of node.js videos coming up uh I’ve already recorded some videos on how to do deployments with node.js automated deployments fun stuff but first I wanted to answer the question uh with an introductory video of what is node.js I’ve had a lot of people ask me this
People are saying stuff like hey I’ve been doing PHP for a lot of years uh but I don’t exactly get what node.js is sounds confusing seems like it means a lot of different things and it kind of does to some people so we’re going to answer that uh the simple question is or
The simple answer is is the makers of node.js took JavaScript which is normally confined to a browser and they allowed it to run on your computer so normally you know JavaScript runs in the browser it can only access your web page uh but when you allow it to run when you
Give it a an environment to run on the machine they took Google Chrome’s V8 engine which is an awesome JavaScript engine and now V8 runs on your machine and so this whole new world opens up now you can access the files on your computer which you normally can’t do
With JavaScript you can listen to Network traffic on your computer you can listen to http requests your machine gets and send back a file you can access databases directly all sorts of great stuff basically anything you could do with PHP or Ruby on Rails you can now do
With JavaScript in node.js and so there’s basically two categories of what people are doing with node they’re building utilities on the machine which is like utilities for your day in day out development that would be gulp grunt yman you know uh you know things that you’ll concatenate and build JavaScript
Files with or it’ll listen to file system changes and it’ll do live reload or you know whenever you save a SAS file it will automatically convert a CSS file utilities on your machine if you say a job description if you see a job description that says you know front end
Developer no js’s in there somewhere they probably referring to this kind of node.js if you see a job description that says node.js engineer node.js developer they’re probably talking to the other use case which is let’s build a web server a web application with node instead of using Ruby on Rails PHP
Python we’re going to use Express framework for node.js or COA framework for nodejs or whatever and we’re going to build our web application in this and so that’s kind of what the other use case is so so let’s do some super Basics on how this node.js thing works well for
One if you go to nodejs.org you can install it on your machine then you can type node DV there you go I’ve got a version I can actually just type node right now and now I’m running a process a process you know kind of a program that’s running on your computer I’ve now
Created a new process I can type JavaScript ver a equals 1 and type A A equals 1 just like I would normally do on a console but what’s different about this is this process right here runs within window so if I go ver a equals 1 then window. a equals 1 because window
Is my Global scope there is no window object on a node.js process because there’s no window uh what there is is a global object Global a equals 1 and then there’s also no document object uh JavaScript has a global document object which is my HTML document that this
Thing’s built upon well this isn’t tied to an HTML document it’s tied to a process uh which is the actual program process that’s running right now so I have a process object and that’s kind of two differences I’m going to control C twice to get out of that uh and you can
Also I have my module 1js right here you can also run node module one um and I don’t have to put JS but I can and so it runs this and exits cuz nothing’s happening so I can go console log High and then I can run that again hi now you
Can do ver a equals 1 console log a and then run that again says hi it says one so that’s kind of how you’ll actually execute files just like you would execute PHP files or something like that on your machine and how they let’s get into modules real quick um how
Modules work within node because this is going to apply either way and I’m probably I’m pretty much only going to get into two modules npm and a basic web server and then we’re done and that’s kind of going to give you the overall scope of how you program in node.js so
Modules are how you basically load one file into another if you’ve used required JS you already get the concept let’s go there to uh M2 equals require module 2 so that’s saying before I do any more code I need to load in module 2 so here’s my module 2 I actually have to
Do this which means I’m looking for a file in the same directory or I could go uh you know if there was other folders going on here I could go folder 2/m module 2 it basically assumes JS is added just like you know if you were
Running a file over here so in this case it’s in the same directory I’m just going to require. module 2 and let’s console log this M2 run it and module 2 is a function let’s delete that that’s from earlier stuff that I was testing the video module 2 is an empty object because
Module 2 is not exporting anything at all I can go ver a equals 1 run it still nothing I’ve defined ver a in here but I’m not exporting that to get this from module 2 into module one it’s whatever is exporting from module 2 is what will
Get passed into this M2 variable so if I go module exports a equal a so now I’m assigning a to module exports a there you go now the value of a is one I can go module exports b equals 2 and now you see I’m just basically
Building a whole object uh you can also shorthand this you can just go exports exports a equals that same thing works just fine or you can override the entire module exports object and make it a function so module two so now I can actually go
M2 equals require module 2 and I can run M2 because it’s a function now so there you go when I run function module 2 it’s going to console log it so that’s kind of how modules work uh that’s kind of how your separation of files Works in node.js
And what they’ve also built is this node package manager which is npm it comes with with node and that allows you to actually download um and manage packages which is really cool so I can go npm install underscore it’s pretty popular module so now it made a node modules
Folder and it added underscore in there and so now I can actually go there equals require underscore no no file path no Dot SL just underscore and so that’s going to look in my node modules folder for the underscore module and the underscore package will tell me what
File that loads and that is by default just going to load underscore so now I can go uh C console log my underscore character and when I run module one you see that’s the whole under _ Library awesome super cool so npm is a super easy way of installing common
Things um and then the other piece to npm is ideally you want to save them in a package if you’re working on a project and you have 15 different node modules you don’t want to have you don’t want to have to run npm install every time somebody downloads your you know GitHub
Repository and needs these dependencies you want to be able to save the many dependencies you have so you’ll actually run npm and nit and we’re actually going to start an npm package here real quick name what is node sure sure sure sure sure sure sure um and so I just said
Okay to everything and it made a package Json file for me and so it’s called what is node has a version blah blah blah and you see it already added underscore as a dependency for me because I’ve already installed that so now I can do npm install
Backbone if I run npm install backbone it added to my node modules as well but it did not add to my package Json because I didn’t do the flash s or slash dash s flag so now if i do- s that’s for save you can see that it now added
Backbone in here into my package Json as well um and so now I’ve got the two going on let’s say I delete this node modules folder Al together bye-bye go away you don’t want to keep the node modules in so now my my whole node project consists of this one package
Json file and all I have to do is go npm install npm install is going to look through all the dependencies and it’s going to get them all there you go now I’ve got all my node modules and now everything’s going to work I can require UND underscore
Again so that’s kind of if that made sense that’s how npm Works npm allows you to maintain all your dependencies one of the awesome things about node is there’s thousands and thousands of dependencies that people are building all the time that allow you to do cool things like uh you know access web
Services or log into Google with your Google email address there’s packages out there for all this stuff so in node you can just load in a package real time the package will do the dirty work for you and you can focus on building your application let’s look at the HTTP
Package which is what we use to make a basic web server we don’t have to install this with npm because it comes built into node HTTP and we can go HTTP create server and let’s give that a function whoops and we’ll go ver server equals that returns a
Server and that server can listen to Port 3002 normally run node stuff on Port 3000 actually so we’ll do Port 3000 makes this a little bigger here so now I’m going to create a web server and that web server will get request response and so whenever I get an
Incoming request on Port 3000 this function will fire and I get to access what they’re requesting and I get to actually make a little response so I’m going to do is I’m going to console log got a request and I’m going to do response dot WR hi and I’m going to
Response.end there we go and now let’s run this so you notice it runs and it keeps running it doesn’t stop because there is an open server running that’s listening to any request on Port 3000 so if I go to Port 3000 it says hi and it says hey
I got a request let’s do it again nice got another request it’s sent back high if I keep doing this it’s going to keep saying hey I got a request I got a request let’s send high back every time super cool it’s super awesome and so
That’s kind of how you build a basic web server um you could listen to if I went Local Host 3000 slash give me a file then it’s still just going to say hey because there’s no smart code in here listening to what the path is and what
We’re going to do with that path and so but we could listen to the path and if the path is image. jpeg we could go get image. JPEG and respond back with that so that’s kind of what node.js is from here on out you get to mess around with
It if you want to learn how to build an Express web app then I have a video on that already I’m going to put that video the description and that’s an introduction to nodejs
-
Sale!
Wireless WIFI Repeater Extender Amplifier Booster 300Mbps
$29.99$14.99 Add to cartWireless WIFI Repeater Extender Amplifier Booster 300Mbps
Categories: Electronics, Wi-Fi Router, Wireless Wi-Fi Extender Tags: 300Mbps, 802.11N, Amplifier, Booster, Extender, mobile wi-fi booster, Remote, WIFI, Wireless, Wireless WIFI, Wireless WIFI Repeater, Wireless WIFI Repeater Extender, Wireless WIFI Repeater Extender Amplifier, Wireless WIFI Repeater Extender Amplifier Booster, Wireless WIFI Repeater Extender Amplifier Booster 300Mbps$29.99$14.99 -
Sale!
Full RGB Light Design Gaming Headset Headphones with Mic
$24.99$14.99 Add to cartFull RGB Light Design Gaming Headset Headphones with Mic
Categories: Electronics, Gaming, Gaming Headsets Tags: Design, Full, Full RGB Light Design Gaming Headset, Full RGB Light Design Gaming Headset Headphones, Full RGB Light Design Gaming Headset Headphones with Mic, Gamer, Gaming, Gaming Headset Headphones, gaming headset wireless, Headphone, Headphones, Headset, Light, Mic, Package, RGB$24.99$14.99 -
Sale!
Wireless BlueTooth Multi-Device Keyboard Mouse Combo
$39.99$19.99 Add to cartWireless BlueTooth Multi-Device Keyboard Mouse Combo
Categories: Electronics, Gaming, Gaming Keyboards, Keyboard Mouse Combos Tags: Combo, Keyboard, keyboard mouse combos, Mouse, MultiDevice, Set, WireKeyboard Mouse Combo, Wireless, Wireless BlueTooth Keyboard Mouse Combo, Wireless BlueTooth Keyboard Mouse Combos, Wireless BlueTooth Multi-Device Keyboard Mouse Combo, Wireless BlueTooth Multi-Device Keyboard Mouse Combos$39.99$19.99 -
Sale!
High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar
$199.99$139.99 Add to cartHigh Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar
Categories: Gaming, Gaming Chairs Tags: Adjustable, Chair, computer chairs, Desk, Executive, Gaming, Girl, Headrest, High, High Back Leather Executive Adjustable Swivel Gaming Chair, High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest, High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar, High Back Leather Executive Adjustable Swivel Gaming Chairs, Leather, Lumbar, Office, Racing, Swivel$199.99$139.99 -
Sale!
Professional LED Light Wired Gaming Headphones with Noise Cancelling Microphone
$29.99$19.99 Select optionsProfessional LED Light Wired Gaming Headphones with Noise Cancelling Microphone
SKU: N/A Categories: Electronics, Gaming, Gaming Headsets Tags: Cancelling, Gaming, Gaming Headphones with Noise Cancelling Microphone, gaming headset, Headphones, Headset, LED, Light, Mic, Microphone, Noise, Professional, Professional LED Light Wired Gaming Headphones, Professional LED Light Wired Gaming Headphones with Noise Cancelling Microphone, Wired, Wired Gaming Headphones, Wired Gaming Headphones with Noise Cancelling Microphone$29.99$19.99 -
Sale!
Gaming Desk with LED Lights USB Power Outlets and Charging Ports
$349.99$249.99 Select optionsGaming Desk with LED Lights USB Power Outlets and Charging Ports
SKU: N/A Categories: Computer Desk, Gaming, Gaming Desk Tags: and Charging Ports, Charging, Desk, Desks, Gaming, gaming desk with led lights, Gaming Desks with LED Lights, Home, LED, Lights, Monitor, Office, Outlets, Port, Power, Room, Stand, USB, USB Power Outlets, White, Workstation$349.99$249.99 -
Sale!
Wired Mixed Backlit Anti-Ghosting Gaming Keyboard
$99.99$79.99 Add to cartWired Mixed Backlit Anti-Ghosting Gaming Keyboard
Categories: Electronics, Gaming, Gaming Keyboards Tags: Antighosting, Backlit, Blue, brown, Gaming, Gaming Keyboard, gaming keyboards, gaming keyboards and mouse, Keyboard, Laptop, Switch, Wired, Wired Mixed Backlit Anti-Ghosting Gaming Keyboard, Wired Mixed Backlit Anti-Ghosting Gaming Keyboards, Wired Mixed Backlit Gaming Keyboard$99.99$79.99 -
Sale!
Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset
$119.99$59.99 Add to cartWireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset
Categories: Electronics, Gaming, Gaming Headsets Tags: 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset, ANC, Audio, Bluetooth, Cancellation, Ear, Earphone, gaming headset, Headphones, Headset, Hi-Res Over the Ear Headphones Headset, HiRes, Noise, Wireless, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Headphones, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headsets$119.99$59.99 -
Sale!
Wired Sports Gaming Headset Earbuds with Microphone
$19.99$9.99 Select optionsWired Sports Gaming Headset Earbuds with Microphone
SKU: N/A Categories: Gaming, Gaming Headsets Tags: Accessories, Earbud, Earphone, Earphones, Gaming, gaming headset with microphone, Headphones, Headset, IOS, Microphone, Sports, Wired, Wired Sports Gaming Headset Earbuds, Wired Sports Gaming Headset Earbuds with Microphone, Wired Sports Headset Earbuds$19.99$9.99 -
Sale!
150W Universal Multi USB Fast Charger 16 Port MAX Charging Station
$49.99$29.99 Add to cart150W Universal Multi USB Fast Charger 16 Port MAX Charging Station
Categories: Charging Stations, Electronics Tags: 150W, 150W Charging Station, 150W Universal Multi USB Charging Station, 150W Universal Multi USB Fast Charger 16 Port MAX Charging Station, 150W Universal Multi USB Fast Charger 16 Port MAX Charging Stations, 150W Universal Multi USB MAX Charging Station, 16 Port MAX Charging Station, 3.5A, Charger, Charging, Fast, laptop charging stations, Max, Multi, Port, Stand, Station, Universal, USB$49.99$29.99
Is this being run on command line?
FINALLY what i was actually looking for
thanks bro, this is likely the best video on this topic to this day
Tell me why a video from 8 years ago explains node.js much better than any other video until now? You rock man
thank you!
Very good @2022
What a nice intro! The only thing lacking here (for me) is a reference to the Docs of NodeJS (or an explanation if they even exist or not).
This video made me fart several times.
Super cool thanks
Watching this video was the "Ahaa!" moment for me with respect to Node.
Thanks a lot.
This is the tutorial of node js which I am looking for.
Clear every doubt in 13 minutes only
Thanks again.
thanks for the video.
indeed an excelent introduction to node! thanks!
critical role campaign 1
chills
1000% wow
numb
please i need you. mail me: zakariaqe2334@gmail.com
What is Node.js Exactly ?
mandalorian
trey songz
really appreciate the large font!
critical role season 2
Very useful video
npm install (grow a) backbone
Thank you! This video really helped me out.
JavaScript and Mac? That's funny. Real coder over here.