3. What is JavaScript ?
It is dynamic programming language.
It is client side script to interact with user.
It most commonly used as a part of web browser
4. Background
Node.js was invented in 2009 by Ryan Dahl
inspired to create Node.js after seeing a file upload progress bar on
FLICKR
Open source , sponsored by Joyent and Microsoft
Ryan was a mathematics student and dropped out of college.
Node.js runs on V8.
5. Introduction: Basic
What is NodeJS ?
NodeJS is an open source , cross platform runtime environment for
server side and networking application.
It is written in JavaScript and can run on Linux , Mac , Windows ,
FreeBSD.
It provided an event driven architecture and a non blocking I/O that
optimize and scalability. These technology uses for real time application.
It used Google JavaScript V8 Engine to Execute Code.
6. JavaScript V8 Engine
The V8 JavaScript Engine is an open source JavaScript engine
developed by Google for the Google Chrome web browser.
V8 compiles JavaScript to native machine code (IA-32, x86-64,
ARM, or MIPS ISAs) before executing it.
V8 can run standalone, or can be embedded into any
C++ application
7. Why Use NodeJS?
Node's goal is to provide an easy way to build scalable network programs.
What is unique about NodeJS?
Using JavaScript on server-side making communication between client and
server will happen in same language.
Servers are Event based serves each request in Evented Loop. So, it can
handle simultaneous requests.
8. Reasons touse NodeJS
It is very lightweight and fast. There has been over 200,000 visits on
this website in three weeks and minimal server resources has been
able to handle it all.
The counter is really easy to make to be real time.
Node.js was easy to configure.
There are lots of modules available for free.
NodeJS work with NoSQL as well.
9. When not use NodeJS
Your server request is dependent on heavy CPU consuming algorithm/Job.
NodeJS Setup
Download at http://nodejs.org
Set Environment variable (Last version automatic set)
Open command line and type following.
node -v
10. What is Callback?
Call-back is an asynchronous equivalent for a function.
A call-back function is called at the completion of a given task.
Node makes heavy use of call-backs.
11. Blocking I/O:
Traditional applications waits for a set code to complete before it displays the
content. This is called blocking code.
12. Non blocking I/O:
In non blocking Once the request is made we continue on to the next line of
code before waiting for the time consuming request to finish.
Uses callback functions to handle non blocking code.
13. What makes node better?
Event driven
• Just like java script events on the client, Node can handle various events
on the server
• Examples of server events are file transfer , request for a page , loading
content from database
15. REPL Terminal
Read − Reads user's input, parses the input into JavaScript data-structure, and stores
in memory.
Eval − Takes and evaluates the data structure.
Print − Prints the result.
Loop − Loops the above command until the user presses ctrl-c twice.
Starting REPL
Simple Expression
node
>
node
> 1 + 3
4
>1 + ( 2 * 3 ) - 4
3
>
16. REPL Commands
ctrl + c − terminate the current command.
ctrl + c twice − terminate the Node REPL.
ctrl + d − terminate the Node REPL.
Up/Down Keys − see command history and modify previous commands.
tab Keys − list of current commands.
.help − list of all commands.
.break − exit from multiline expression.
.clear − exit from multiline expression.
.save filename − save the current Node REPL session to a file.
.load filename − load file content in current Node REPL session.
17. What is npm?
NPM
Easy for developers to share
and reuse code
Makes it easy to update the
code that you’re sharing
19. The npm comes bundled with Node.js installables in versions after that v0.6.3.
You can check the version by command.
npm –v (or) npm version
20. Installing Modules using npm
Following is the syntax to install any Node.js module:
For example:
npm install <Module Name>
npm install express
21. Local Installation
Global Installation
• Local
Mode
Package
installation
• Node
module
accessible
• require()
command
• Npm ls
• Global
Mode
Package
installation
• System
Directory
Not-
accessible
• Require()
command
• Npm ls -
g
CLI
22. Uninstalling a Module
npm uninstall express
Updating a Module
npm update express
Search a Module
npm search express
23. BUFFER
For an input operation, buffer mode will wait until all the data is collected
into a buffer
and then pass it to a call-back as soon as the entire resource is read.
In the below image you can see that when some data are received it is saved
into the buffer.
But when everything is received i.e. the final one which causes the entire
buffer to be sent to the customer.
24. STREAMS
Whereas stream will allow you to process the data as soon as it arrives from
the resource.
In the below image each new chunk of data is received from the resource is
immediately provided to the consumer,
thus consumer can process the data straightaway without waiting for all the
data to be collected in the buffer.
25. Stream Types
Types of
Streams
used for read
operation.
Readable
used for write
operation.
Writeable
used for both
read and write
operation.
Duplex
output is
computed
based on
input.
Transform
26. File System
Node implements File I/O using simple wrappers around standard POSIX
functions.
The Node File System (fs) module can be imported using the following
syntax
File system is of 2 types (i) Synchronous (ii) Asynchronous
Synchronous:
synchronous method never blocks a program during its execution, whereas
the second one does.
var fs = require("fs")
27. Asynchronous
Asynchronous methods take the last parameter as the completion function
call-back and the first parameter of the call-back function as error.
It is better to use an asynchronous method instead of a synchronous method
28. Scalable
Node applications are highly
scalable
Horizontal scaling of servers
Adding more servers instead of
increasing the performance of
each
29. What is a Web Server?
A Web Server is a software application which handles HTTP requests
sent by the HTTP client, like web browsers, and returns web pages in
response to the clients.
Web servers usually deliver html documents along with images, style sheets,
and scripts.
Most of the web servers support server-side scripts
30. Web Application Architecture
Client − This layer consists of web browsers, mobile browsers or
applications which can make HTTP requests to the web server.
Server − This layer has the Web server which can intercept the requests
made by the clients and pass them the response.
Business − This layer contains the application server which is utilized by the
web server to do the required processing. This layer interacts with the data
layer via the database or some external programs.
Data − This layer contains the databases or any other source of data.
37. ❖ NoSqL cross-platform document-oriented
database system
❖ JSON-like documents with dynamicschemas
❖ Easier & faster to send data between
❖ client and server (b/cdata saved in JSON format)
❖ Local Install:
➡MongoDB: http://www.mongodb.org/
❖ MongoDB-as-a-Service:
➡ Modulus:https://modulus.io
➡ Mongolab:https://mongolab.com
38. ❖ A lightweight framework used to build single and
multi-page web applications inNode.JS
❖ Wrapper for the core Node.js HTTP
module objects.
❖ Provides functions for everything you may
need to build a modern webserver
❖ Learn More: http://expressjs.com
express
40. JavaScript platform built on V8❖ Server-side
engine
❖ Helps building highly scalable and concurrent
applications rapidly
❖ Makes multithreaded servereasy
❖ Event based concurrency
❖ Easy to modify and maintains apps, due
to piped modules
❖ Install fromhttp://nodejs.org
41. APPS SUITED FORNODE.JS
❖ E-Commerce
❖ Payment
Processing
❖ Social Media
❖ RealtimeServices
❖ MediaApplications
❖ Enterprise
Services