Quick introduction about Node.js, what is it? What is Node not?
What is V8 engine?
How to Install Node.js
github: https://github.com/elbassel/MEAN-Training.git
2. Agenda
Story of Node Js
V8 JavaScript Engine
Platform Vs Framework
What is node?
What Is Node not?
Blocking code
Asynchronous: the browser
Asynchronous: the server
Event Loop
Modularity
Installing
3. Story of Node Js
Inventor: Ryan Dahl
Ryan Dahl is a math student but he decided to go with programming.
4. Story of Node Js
Once upon a time he was uploading image using flickr, and there is was no
status bar.
And that was the push to Node JS creation.
5. V8 JavaScript Engine
V8 is Google's open source JavaScript engine.
V8 is written in C++ and is used in Google Chrome, the open source browser from Google.
V8 can run standalone, or can be embedded into any C++ application.
6. Platform VS Framework
What is Software platform?
- A software platform is, in the most general sense, whatever pre-existing environment a
piece of computer software or code object is designed to run within, obeying its
constraints, and making use of its facilities.
What is a Software framework?
- For me, it’s a tool that helps you develop application in a specific way, providing specific
functions you don’t have to do everytime.
- Here is an awesome example.
7. What is Node.js?
Node.js® is a platform built on Chrome's JavaScript runtime for easily building
fast, scalable network applications. Node.js uses an event-driven, non-blocking
I/O model that makes it lightweight and efficient, perfect for data-intensive real-
time applications that run across distributed devices.
8. What is Node.js?
Built on JS:
The dream of Java write once run everywhere, everyone has it now :)
JS is unavoidable, you will write JS code.
When AJAX has released. JS started to evolve rapidly.
Moreover, because Mozilla, Microsoft, google, opera, started to develop
it.
9. What is Node.js?
Node.js uses the Google V8 JavaScript engine to execute code, and a large
percentage of the basic modules are written in JavaScript. Node.js
contains a built-in library to allow applications to act as a Web server
without software such as Apache HTTP Server or IIS.
10. What is Node.js?
Node.js is gaining adoption as a server-side platform and is used by
Microsoft, Yahoo!, Walmart, Groupon,SAP, LinkedIn, Rakuten,
PayPal,Voxer,and GoDaddy.
11. What is Node.js?
Dahl was guided by a few rigid principles:
A Node program/process runs on a single thread, ordering execution through an event
loop.
Web applications are I/O intensive, so the focus should be on making I/O fast
Program flow is always directed through asynchronous callbacks
Complex programs should be assembled from simpler programs
12. What Is Node not?
● It is not a web framework.
● For Beginners.
○ It requires more knowledge to work with it.
● Multi-threaded.
13. Blocking code
The most common task that any developer would do is File I/O, this being a very fundamental process
:
- Open a File.
- Read it's contents and print.
- Do something else.
- For two files, suppose each file
needs 5 seconds to be read.
14. Blocking code
Notes on the previous code:
It's a blocking code, until the read operation is completed, the next lines of
code is not executed.
It takes 10 seconds to read both files.
5 seconds 5 seconds
15. Asynchronous: the browser
Node uses event-driven and non blocking I/O model.
At the browser:
$.get('/getData’, function(response){
console.log('my responset' + response);
});
16. Asynchronous: the server
It brings the asynchronous model to the server too.
Non-blocking code:
A waiting process is a wasteful process, especially when waiting for I/O.
17. Asynchronous: the server
It’s non-blocking code, it’s it takes only 5 seconds to read both files:
5 seconds
5 seconds
18. Event Loop
What is the Event Loop?
The event loop is what allows Node.js to perform non-blocking I/O operations.
despite the fact that JavaScript is single-threaded — by offloading operations to
the system kernel whenever possible.
Since most modern kernels are multi-threaded, they can handle multiple
operations executing in the background. When one of these operations
completes, the kernel tells Node.js so that the appropriate callback may be
added to the poll queue to eventually be executed.
19. Modularity
In the book The Art of Unix Programming, Eric Raymond proposed the Rule
of Modularity:
Developers should build a program out of simple parts connected by well defined interfaces, so
problems are local, and parts of the program can be replaced in future versions to support new
features. This rule aims to save time on debugging complex code that is complex, long, and
unreadable.
21. Installing
Windows:
- go to Node website: https://nodejs.org/
- download the node version based on your Windows system(32 - 64)
22.
23.
24.
25.
26.
27.
28. Installing
Ubuntu:
sudo apt-get update
sudo apt-get install nodejs
Then, Node.js is installed, open a new terminal and write comman
node and press enter.
You can write JS code there.
29. Installing
Mac:
- Go to: https://nodejs.org/en/download/
- Click Macintosh installer to download
- Double click to install
- Then, Node.js is installed, open a new terminal and write command
node and press enter.
- You can write JS code there.