SlideShare a Scribd company logo
1 of 28
NodeJS: Chapter 1
7 Nov 2020
Agenda
• Introduction
• Install nodejs
• Hello nodejs
• Nodejs module system
• Event loop
• Npm, yarn
• Create a project
• Frameworks
2
Introduction
• Open source, cross browser, runtime environment
• Executes javascript code on the server
• Build backend services
• Highy scalable, data intensive, and real time apps,
NOT for CPU intensive apps
3
Introduction
• Fewer lines, fewer files, fewer developers, more
requests, faster response
• JavaScript everywhere
• Clean, consistent, similar code on FE and BE
• Latest ECMAScript standards
• Many open source libraries
• Asynchronous I/O (unlike asp.net, ruby ...)
4
Introduction
• Who uses Node.js?
• GoDaddy, Groupon, IBM, LinkedIn, Microsoft,
Netflix, PayPal, SAP, Walmart, Yahoo, Amazon
Web Service
5
Introduction
• Browser = JS engine + browser code
• Nodejs = JS engine + C/C++ code
• Javasciprt = a programming language
• Nodejs = a runtime
• Express, Nest etc. = Nodejs Frameworks
6
Install nodejs
https://nodejs.org/en/
7
Hello nodejs
• Demo
8
Nodejs module system
• Module = sub program, packages as a unit
• CommonJS module system
• Each file is a separate module
• Use “require”
• Private & Public
• Module wrapper function
9
Event Loop
10
Call Stack
Event Queue
Some APIs
Npm, Yarn
• Download and manage dependencies
• Also used in frontend javascript projects
• Yarn: an alternative to npm
• Yet another resource negotiator
• Npm: after few years on Node.js
• Yarn (by facebook): to fix performance and security
concerns of npm
• yarn licenses list
• Yarn why package-name
11
Create a project
• Demo
12
Node.js frameworks
• https://nodejs.dev/learn#nodejs-frameworks-and-
tools
13
Next Topics
• Asynchronous Programming
• Some essential core modules
• Testcases in NodeJS
14
Asynchronous Programming
• JavaScript is synchronous by default and is single
threaded.
• Computers are asynchronous .
• Multiple process could be executed at the same
time.
• Normally, programming languages are
synchronous, and some provide a way to manage
asynchronicity, in the language or through
libraries.
15
Asynchronous Programming
• Node.js introduced a non-blocking I/O
environment to extend this concept to file access,
network calls and so on
• There are different ways to achieve asynchronous
programming in node js.
16
Different ways of Asynchronous
Programming
Need of asynchronous -:
Different I/O operations(File read/write,DB
operations,making http calls)
• Callbacks
• Promises
• Async-await
17
Callbacks
A callback is a simple function that's passed as a
value to another function and will only be executed
when the event happens.
(Events could be button click, api call, customized
event)
Demo-
18
Callbacks
• Callbacks are great for simple cases!
• However every callback adds a level of nesting,
and when you have lots of callbacks, the code
starts to be complicated very quickly.
19
Promises
A promise is an object that may produce a single
value some time in the future: either a resolved
value, or a reason that it’s not resolved (e.g., a
network error occurred)
20
Promises
• Once a promise has been called, it will start in
pending state. This means that the caller function
continues the execution, while it waits for the
promise to do its own processing, and give the
caller function some feedback.
Demo-
21
Async-Await
• Promises were introduced to solve the famous
callback hell problem, but they introduced
complexity on their own, and syntax complexity
• They were good primitives around which a better
syntax could be exposed to the developers, so
when the time was right we got async functions.
• They make the code look like it's synchronous, but
it's asynchronous and non-blocking behind the
scenes.
22
Async-Await
Async-
It simply allows us to write promises based code as
if it was synchronous and it checks that we are not
breaking the execution thread. It operates
asynchronously via the event-loop. Async functions
will always return a value. It makes sure that a
promise is returned and if it is not returned then
javascript automatically wraps it in a promise which
is resolved with its value.
23
Some essential core modules
While numerous libraries are available for extending
Node's functionalities, the engine comes with a set
of core modules implementing basic functionalities.
There's currently 34 core modules included in Node.
fs,path,os,events,http
24
fs
The fs module provides a lot of very useful
functionality to access and interact with the file
system.
All methods in this module are async in nature but
we can get sync as well by adding sync.
25
event,http
• The events module provides us the EventEmitter
class, which is key to working with events in Node.
• The http module of Node.js provides useful
functions and classes to build an HTTP server
26
Writing testcases in NodeJS
• Testing is a key element to any application. For
Node.js, the framework available for Testing is
called Jasmine. In early 2000, there was a
framework for testing JavaScript applications
called JsUnit. Later this framework got upgraded
and is now known as Jasmine.
27
Coming Soon…….
• Web-Socket in NodeJS
• Worker Threads
• Cluster mode
28

More Related Content

What's hot

What's hot (20)

Node.js architecture (EN)
Node.js architecture (EN)Node.js architecture (EN)
Node.js architecture (EN)
 
The new Netflix API
The new Netflix APIThe new Netflix API
The new Netflix API
 
Microservices with AWS Lambda and the Serverless Framework
Microservices with AWS Lambda and the Serverless FrameworkMicroservices with AWS Lambda and the Serverless Framework
Microservices with AWS Lambda and the Serverless Framework
 
Nodejs overview
Nodejs overviewNodejs overview
Nodejs overview
 
Scalability using Node.js
Scalability using Node.jsScalability using Node.js
Scalability using Node.js
 
Javantura v4 - Self-service app deployment with Kubernetes and OpenShift - Ma...
Javantura v4 - Self-service app deployment with Kubernetes and OpenShift - Ma...Javantura v4 - Self-service app deployment with Kubernetes and OpenShift - Ma...
Javantura v4 - Self-service app deployment with Kubernetes and OpenShift - Ma...
 
2017 Microservices Practitioner Virtual Summit: The Mechanics of Deploying En...
2017 Microservices Practitioner Virtual Summit: The Mechanics of Deploying En...2017 Microservices Practitioner Virtual Summit: The Mechanics of Deploying En...
2017 Microservices Practitioner Virtual Summit: The Mechanics of Deploying En...
 
Dot net platform and dotnet core fundamentals
Dot net platform and dotnet core fundamentalsDot net platform and dotnet core fundamentals
Dot net platform and dotnet core fundamentals
 
Serverless architecture: introduction & first steps
Serverless architecture: introduction & first stepsServerless architecture: introduction & first steps
Serverless architecture: introduction & first steps
 
NetflixOSS for Triangle Devops Oct 2013
NetflixOSS for Triangle Devops Oct 2013NetflixOSS for Triangle Devops Oct 2013
NetflixOSS for Triangle Devops Oct 2013
 
5 Popular Choices for NoSQL on a Microsoft Platform - All Things Open - Octob...
5 Popular Choices for NoSQL on a Microsoft Platform - All Things Open - Octob...5 Popular Choices for NoSQL on a Microsoft Platform - All Things Open - Octob...
5 Popular Choices for NoSQL on a Microsoft Platform - All Things Open - Octob...
 
2016 07 - CloudBridge Python library (XSEDE16)
2016 07 - CloudBridge Python library (XSEDE16)2016 07 - CloudBridge Python library (XSEDE16)
2016 07 - CloudBridge Python library (XSEDE16)
 
Serverless
ServerlessServerless
Serverless
 
Serverless java
Serverless   javaServerless   java
Serverless java
 
What we do with Go
What we do with GoWhat we do with Go
What we do with Go
 
How to Build Your First Web App in Go
How to Build Your First Web App in GoHow to Build Your First Web App in Go
How to Build Your First Web App in Go
 
Velocity NYC 2016 - Containers @ Netflix
Velocity NYC 2016 - Containers @ NetflixVelocity NYC 2016 - Containers @ Netflix
Velocity NYC 2016 - Containers @ Netflix
 
Docker in Production at the Aurora Team
Docker in Production at the Aurora TeamDocker in Production at the Aurora Team
Docker in Production at the Aurora Team
 
CICD Azure DevOps
CICD Azure DevOpsCICD Azure DevOps
CICD Azure DevOps
 
DockerCon SF 2015: The Distributed System Toolkit
DockerCon SF 2015: The Distributed System ToolkitDockerCon SF 2015: The Distributed System Toolkit
DockerCon SF 2015: The Distributed System Toolkit
 

Similar to Node.js Chapter1

Similar to Node.js Chapter1 (20)

Node js internal
Node js internalNode js internal
Node js internal
 
FITC - Node.js 101
FITC - Node.js 101FITC - Node.js 101
FITC - Node.js 101
 
Beginners Node.js
Beginners Node.jsBeginners Node.js
Beginners Node.js
 
Node.js meetup at Palo Alto Networks Tel Aviv
Node.js meetup at Palo Alto Networks Tel AvivNode.js meetup at Palo Alto Networks Tel Aviv
Node.js meetup at Palo Alto Networks Tel Aviv
 
IoT Node-Red Presentation
IoT  Node-Red PresentationIoT  Node-Red Presentation
IoT Node-Red Presentation
 
Node.js 101 with Rami Sayar
Node.js 101 with Rami SayarNode.js 101 with Rami Sayar
Node.js 101 with Rami Sayar
 
Mini-Training: Node.js
Mini-Training: Node.jsMini-Training: Node.js
Mini-Training: Node.js
 
02 Node introduction
02 Node introduction02 Node introduction
02 Node introduction
 
A brief intro to nodejs
A brief intro to nodejsA brief intro to nodejs
A brief intro to nodejs
 
Kalp Corporate Node JS Perfect Guide
Kalp Corporate Node JS Perfect GuideKalp Corporate Node JS Perfect Guide
Kalp Corporate Node JS Perfect Guide
 
Intro to Node.js (v1)
Intro to Node.js (v1)Intro to Node.js (v1)
Intro to Node.js (v1)
 
Tech io nodejs_20130531_v0.6
Tech io nodejs_20130531_v0.6Tech io nodejs_20130531_v0.6
Tech io nodejs_20130531_v0.6
 
Introduction to Node JS.pdf
Introduction to Node JS.pdfIntroduction to Node JS.pdf
Introduction to Node JS.pdf
 
Vert.x keynote for EclipseCon 2013
Vert.x keynote for EclipseCon 2013Vert.x keynote for EclipseCon 2013
Vert.x keynote for EclipseCon 2013
 
20120306 dublin js
20120306 dublin js20120306 dublin js
20120306 dublin js
 
Nodejs
NodejsNodejs
Nodejs
 
Node Architecture.pptx
Node Architecture.pptxNode Architecture.pptx
Node Architecture.pptx
 
"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)
"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)
"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)
 
Introduction to node.js aka NodeJS
Introduction to node.js aka NodeJSIntroduction to node.js aka NodeJS
Introduction to node.js aka NodeJS
 
ServerSentEvents.pdf
ServerSentEvents.pdfServerSentEvents.pdf
ServerSentEvents.pdf
 

More from Talentica Software

Android Media Player Development
Android Media Player DevelopmentAndroid Media Player Development
Android Media Player Development
Talentica Software
 

More from Talentica Software (20)

Typescript: Beginner to Advanced
Typescript: Beginner to AdvancedTypescript: Beginner to Advanced
Typescript: Beginner to Advanced
 
Web 3.0
Web 3.0Web 3.0
Web 3.0
 
Remix
RemixRemix
Remix
 
Web Performance & Latest in React
Web Performance & Latest in ReactWeb Performance & Latest in React
Web Performance & Latest in React
 
Nodejs Chapter 3 - Design Pattern
Nodejs Chapter 3 - Design PatternNodejs Chapter 3 - Design Pattern
Nodejs Chapter 3 - Design Pattern
 
Node js Chapter-2
Node js Chapter-2Node js Chapter-2
Node js Chapter-2
 
Micro Frontends
Micro FrontendsMicro Frontends
Micro Frontends
 
Test Policy and Practices
Test Policy and PracticesTest Policy and Practices
Test Policy and Practices
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
 
Setting Up Development Environment For Google App Engine & Python | Talentica
Setting Up Development Environment For Google App Engine & Python | TalenticaSetting Up Development Environment For Google App Engine & Python | Talentica
Setting Up Development Environment For Google App Engine & Python | Talentica
 
Connected World in android - Local data sharing and service discovery
Connected World in android - Local data sharing and service discoveryConnected World in android - Local data sharing and service discovery
Connected World in android - Local data sharing and service discovery
 
Mobile App Monetization - Ecosystem & Emerging Trends
Mobile App Monetization - Ecosystem & Emerging TrendsMobile App Monetization - Ecosystem & Emerging Trends
Mobile App Monetization - Ecosystem & Emerging Trends
 
Android Media Player Development
Android Media Player DevelopmentAndroid Media Player Development
Android Media Player Development
 
Cross Platform Mobile Technologies
Cross Platform Mobile TechnologiesCross Platform Mobile Technologies
Cross Platform Mobile Technologies
 
Big Data Technologies - Hadoop
Big Data Technologies - HadoopBig Data Technologies - Hadoop
Big Data Technologies - Hadoop
 
Big Data – Are You Ready?
Big Data – Are You Ready?Big Data – Are You Ready?
Big Data – Are You Ready?
 
Legacy modernization
Legacy modernizationLegacy modernization
Legacy modernization
 
Continous Integration: A Case Study
Continous Integration: A Case StudyContinous Integration: A Case Study
Continous Integration: A Case Study
 
Technology Challenges in Building New Media Applications
Technology Challenges in Building New Media ApplicationsTechnology Challenges in Building New Media Applications
Technology Challenges in Building New Media Applications
 
Flex on Grails - Rich Internet Applications With Rapid Application Development
Flex on Grails - Rich Internet Applications With Rapid Application DevelopmentFlex on Grails - Rich Internet Applications With Rapid Application Development
Flex on Grails - Rich Internet Applications With Rapid Application Development
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 

Node.js Chapter1

  • 2. Agenda • Introduction • Install nodejs • Hello nodejs • Nodejs module system • Event loop • Npm, yarn • Create a project • Frameworks 2
  • 3. Introduction • Open source, cross browser, runtime environment • Executes javascript code on the server • Build backend services • Highy scalable, data intensive, and real time apps, NOT for CPU intensive apps 3
  • 4. Introduction • Fewer lines, fewer files, fewer developers, more requests, faster response • JavaScript everywhere • Clean, consistent, similar code on FE and BE • Latest ECMAScript standards • Many open source libraries • Asynchronous I/O (unlike asp.net, ruby ...) 4
  • 5. Introduction • Who uses Node.js? • GoDaddy, Groupon, IBM, LinkedIn, Microsoft, Netflix, PayPal, SAP, Walmart, Yahoo, Amazon Web Service 5
  • 6. Introduction • Browser = JS engine + browser code • Nodejs = JS engine + C/C++ code • Javasciprt = a programming language • Nodejs = a runtime • Express, Nest etc. = Nodejs Frameworks 6
  • 9. Nodejs module system • Module = sub program, packages as a unit • CommonJS module system • Each file is a separate module • Use “require” • Private & Public • Module wrapper function 9
  • 11. Npm, Yarn • Download and manage dependencies • Also used in frontend javascript projects • Yarn: an alternative to npm • Yet another resource negotiator • Npm: after few years on Node.js • Yarn (by facebook): to fix performance and security concerns of npm • yarn licenses list • Yarn why package-name 11
  • 14. Next Topics • Asynchronous Programming • Some essential core modules • Testcases in NodeJS 14
  • 15. Asynchronous Programming • JavaScript is synchronous by default and is single threaded. • Computers are asynchronous . • Multiple process could be executed at the same time. • Normally, programming languages are synchronous, and some provide a way to manage asynchronicity, in the language or through libraries. 15
  • 16. Asynchronous Programming • Node.js introduced a non-blocking I/O environment to extend this concept to file access, network calls and so on • There are different ways to achieve asynchronous programming in node js. 16
  • 17. Different ways of Asynchronous Programming Need of asynchronous -: Different I/O operations(File read/write,DB operations,making http calls) • Callbacks • Promises • Async-await 17
  • 18. Callbacks A callback is a simple function that's passed as a value to another function and will only be executed when the event happens. (Events could be button click, api call, customized event) Demo- 18
  • 19. Callbacks • Callbacks are great for simple cases! • However every callback adds a level of nesting, and when you have lots of callbacks, the code starts to be complicated very quickly. 19
  • 20. Promises A promise is an object that may produce a single value some time in the future: either a resolved value, or a reason that it’s not resolved (e.g., a network error occurred) 20
  • 21. Promises • Once a promise has been called, it will start in pending state. This means that the caller function continues the execution, while it waits for the promise to do its own processing, and give the caller function some feedback. Demo- 21
  • 22. Async-Await • Promises were introduced to solve the famous callback hell problem, but they introduced complexity on their own, and syntax complexity • They were good primitives around which a better syntax could be exposed to the developers, so when the time was right we got async functions. • They make the code look like it's synchronous, but it's asynchronous and non-blocking behind the scenes. 22
  • 23. Async-Await Async- It simply allows us to write promises based code as if it was synchronous and it checks that we are not breaking the execution thread. It operates asynchronously via the event-loop. Async functions will always return a value. It makes sure that a promise is returned and if it is not returned then javascript automatically wraps it in a promise which is resolved with its value. 23
  • 24. Some essential core modules While numerous libraries are available for extending Node's functionalities, the engine comes with a set of core modules implementing basic functionalities. There's currently 34 core modules included in Node. fs,path,os,events,http 24
  • 25. fs The fs module provides a lot of very useful functionality to access and interact with the file system. All methods in this module are async in nature but we can get sync as well by adding sync. 25
  • 26. event,http • The events module provides us the EventEmitter class, which is key to working with events in Node. • The http module of Node.js provides useful functions and classes to build an HTTP server 26
  • 27. Writing testcases in NodeJS • Testing is a key element to any application. For Node.js, the framework available for Testing is called Jasmine. In early 2000, there was a framework for testing JavaScript applications called JsUnit. Later this framework got upgraded and is now known as Jasmine. 27
  • 28. Coming Soon……. • Web-Socket in NodeJS • Worker Threads • Cluster mode 28