SlideShare a Scribd company logo
1 of 11
Node JS
Index
 Introduction to Node.js
 How to install Node.js
 Differences between Node.js and the Browser
 The V8 JavaScript Engine
 An introduction to the NPM package manager
 ECMAScript 2015 (ES6) and beyond
Introduction to Node.js
Node.js is an open-source and cross-platform JavaScript runtime environment. It is a
popular tool for almost any kind of project!
Node.js runs the V8 JavaScript engine, the core of Google Chrome, outside of the
browser. This allows Node.js to be very performant.
A Node.js app runs in a single process, without creating a new thread for every request.
Node.js provides a set of asynchronous I/O primitives in its standard library that prevent
JavaScript code from blocking and generally, libraries in Node.js are written using non-
blocking paradigms, making blocking behavior the exception rather than the norm.
When Node.js performs an I/O operation, like reading from the network, or accessing a
database or the filesystem, instead of blocking the thread and wasting CPU cycles
waiting, Node.js will resume the operations when the response comes back.
This allows Node.js to handle thousands of concurrent connections with a single server
without introducing the burden of managing thread concurrency, which could be a
significant source of bugs.
Node.js has a unique advantage because millions of frontend developers that write
JavaScript for the browser can now write the server-side code in addition to the client-
side code without needing to learn a completely different language.
In Node.js the new ECMAScript standards can be used without problems, as you don't
have to wait for all your users to update their browsers - you are in charge of deciding
which ECMAScript version to use by changing the Node.js version, and you can also
enable specific experimental features by running Node.js with flags.
An Example Node.js Application
The most common example Hello World of Node.js is a web server:
js
copy
const http = require('HTTP);
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res. set header('Content-Type', 'text/plain');
res.end('Hello Worldn');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
To run this snippet, save it as a server.js file and run node server.js in your
terminal.
This code first includes the Node.js http module.
Node.js has a fantastic standard library, including first-class support for networking.
The createServer() method of HTTP creates a new HTTP server and returns it.
The server is set to listen on the specified port and hostname. When the server is ready,
the callback function is called, in this case informing us that the server is running.
Whenever a new request is received, the request event is called, providing two
objects: a request (an http.IncomingMessage object) and a response
(an http.ServerResponse object).
Those 2 objects are essential to handle the HTTP call.
The first provides the requested details. In this simple example, this is not used, but you
can access the request headers and request data.
The second is used to return data to the caller.
In this case with:
js
res.statusCode = 200;
we set the statusCode property to 200, to indicate a successful response.
We set the Content-Type header:
js
res.set header('Content-Type', 'text/plain');
and we close the response, adding the content as an argument to end():
js
res.end('Hello Worldn');
How to install Node.js
How to install Node.js
Node.js can be installed in different ways. This post highlights the most common and
convenient ones. Official packages for all the major platforms are available
at https://nodejs.dev/download/.
One very convenient way to install Node.js is through a package manager. In this case,
every operating system has its own. Other package managers for MacOS, Linux, and
Windows are listed at https://nodejs.dev/download/package-manager/
nvm is a popular way to run Node.js. It allows you to easily switch the Node.js version,
and install new versions to try and easily roll back if something breaks. It is also very
useful to test your code with old Node.js versions.
See https://github.com/nvm-sh/nvm for more information about this option.
In any case, when Node.js is installed you'll have access to the node executable
program in the command line.
Differences between Node.js and the
Browser
Both the browser and Node.js use JavaScript as their programming language. Building
apps that run in the browser is a completely different thing than building a Node.js
application. Even though it's always JavaScript, some key differences make the
experience radically different.
From the perspective of a frontend developer who extensively uses JavaScript, Node.js
apps bring with them a huge advantage: the comfort of programming everything - the
frontend and the backend - in a single language.
You have a huge opportunity because we know how hard it is to fully, and deeply learn
a programming language, and by using the same language to perform all your work on
the web - both on the client and on the server, you're in a unique position of advantage.
What changes is the ecosystem?
In the browser, most of the time what you are doing is interacting with the DOM or other
Web Platform APIs like Cookies. Those do not exist in Node.js, of course. You don't
have the document, window a, nd all the other objects that are provided by the browser.
And in the browser, we don't have all the nice APIs that Node.js provides through its
modules, like the filesystem access functionality.
Another big difference is that in Node.js you control the environment. Unless you are
building an open-source application that anyone can deploy anywhere, you know which
version of Node.js you will run the application on. Compared to the browser
environment, where you don't get the luxury of choosing what browser your visitors will
use, this is very convenient.
This means that you can write all the modern ES2015+ JavaScript that your Node.js
version supports. Since JavaScript moves so fast, but browsers can be a bit slow to
upgrade, sometimes on the web you are stuck with using older JavaScript / ECMAScript
releases. You can use Babel to transform your code to be ES5-compatible before
shipping it to the browser, but in Node.js, you won't need that.
Another difference is that Node.js supports both the CommonJS and ES module
systems (since Node.js v12), while in the browser we are starting to see the ES
Modules standard being implemented.
In practice, this means that you can use both require() and import in Node.js, while you
are limited to import in the browser.
The V8 JavaScript Engine
V8 is the name of the JavaScript engine that powers Google Chrome. It's the thing that
takes our JavaScript and executes it while browsing with Chrome.
V8 is the JavaScript engine i.e. it parses and executes JavaScript code. The DOM and
the other Web Platform APIs (they all make up runtime environment) are provided by
the browser.
The cool thing is that the JavaScript engine is independent of the browser in which it's
hosted. This key feature enabled the rise of Node.js. V8 was chosen to be the engine
that powered Node.js back in 2009, and as the popularity of Node.js exploded, V8
became the engine that now powers an incredible amount of server-side code written in
JavaScript.
The Node.js ecosystem is huge and thanks to V8 which also powers desktop apps, with
projects like Electron.
Other JS engines
Other browsers have their own JavaScript engine:
 Firefox has SpiderMonkey
 Safari has JavaScriptCore (also called Nitro)
 Edge was originally based on Chakra but has more recently been rebuilt using
Chromium and the V8 engine.
and many others exist as well.
All those engines implement the ECMA ES-262 standard, also called ECMAScript, the
standard used by JavaScript.
The quest for performance
V8 is written in C++, and it's continuously improved. It is portable and runs on Mac,
Windows, Linux, and several other systems.
In this V8 introduction, we will ignore the implementation details of V8: they can be
found on more authoritative sites (e.g. the V8 official site), and they change over time,
often radically.
V8 is always evolving, just like the other JavaScript engines around, to speed up the
Web and the Node.js ecosystem.
On the web, there is a race for performance that's been going on for years, and we (as
users and developers) benefit a lot from this competition because we get faster and
more optimized machines year after year.
Compilation
JavaScript is generally considered an interpreted language, but modern JavaScript
engines no longer just interpret JavaScript, they compile it.
This has been happening since 2009 when the SpiderMonkey JavaScript compiler was
added to Firefox 3.5, and everyone followed this idea.
JavaScript is internally compiled by V8 with just-in-time (JIT) compilation to speed up
the execution.
This might seem counter-intuitive, but since the introduction of Google Maps in 2004,
JavaScript has evolved from a language that was generally executing a few dozens of
lines of code to complete applications with thousands to hundreds of thousands of lines
running in the browser.
Our applications can now run for hours inside a browser, rather than being just a few
form validation rules or simple scripts.
ECMAScript 2015 (ES6) and beyond
Node.js is built against modern versions of V8. By keeping up-to-date with the latest
releases of this engine, we ensure new features from the JavaScript ECMA-262
specification are brought to Node.js developers promptly, as well as continued
performance and stability improvements.
All ECMAScript 2015 (ES6) features are split into three groups for shipping, staged,
and in-progress features:
 All shipping features, which V8 considers stable, are turned on by default on
Node.js and do NOT require any kind of runtime flag.
 Staged features, which are almost completed features that are not considered stable by
the V8 team, require a runtime flag: --harmony.
 In-progress features can be activated individually by their respective harmony flag,
although this is highly discouraged unless for testing purposes. Note: These flags are
exposed by V8 and will potentially change without any deprecation notice.
Which features ship with which Node.js version by default?
The website node. green provides an excellent overview of supported ECMAScript
features in various versions of Node.js, based on Kangax's compat-table.
Which features are in progress?
New features are constantly being added to the V8 engine. Generally speaking, expect
them to land on a future Node.js release, although the timing is unknown.
You may list all the in-progress features available on each Node.js release by grepping
through the --v8-options argument. Please note that these are incomplete and possibly
broken features of V8, so use them at your own risk:
bash
copy
node --v8-options | grep "in progress"
I have my infrastructure set up to leverage the --harmony flag. Should I remove it?
The current behavior of the --harmony flag on Node.js is to enable staged features only.
After all, it is now a synonym of --es_staging. As mentioned above, these are completed
features that have not been considered stable yet. If you want to play safe, especially in
production environments, consider removing this runtime flag until it ships by default on
V8 and, consequently, on Node.js. If you keep this enabled, you should be prepared for
further Node.js upgrades to break your code if V8 changes its semantics to more closely
follow the standard.
How do I find which version of V8 ships with a particular version of Node.js?
Node.js provides a simple way to list all dependencies and respective versions that ship
with a specific binary through the process global object. In the case of the V8 engine,
type the following in your terminal to retrieve its version:
bash
node -p process. versions.v8
An introduction to the NPM package
manager
Introduction to npm
npm is the standard package manager for Node.js.
In September 2022 over 2.1 million packages were reported to be listed in the npm
registry, making it the biggest single language code repository on Earth, and you can be
sure there is a package for (almost!) everything.
It started as a way to download and manage dependencies of Node.js packages, but it
has since become a tool used in frontend JavaScript.
Yarn and ppm are alternatives to npm client. You can check them out as well.
Packages
npm manages downloads of dependencies of your project.
Installing all dependencies
If a project has a package.json file, by running
bash
npm install
It will install everything the project needs, in the node_modules folder, creating it if it does
not exist already.
Installing a single package
You can also install a specific package by running
bash
npm install <package-name>
Furthermore, since npm 5, this command adds <package-name> to
the package.json file dependencies. Before version 5, you needed to add the flag --save.
Often you'll see more flags added to this command:
 --save-dev installs and adds the entry to the package.json file devDependencies
 --No-save installs but does not add the entry to the package.json file dependencies
 --save-optional installs and adds the entry to the package.json file optional
dependencies
 --no-optional will prevent optional dependencies from being installed
Shorthands of the flags can also be used:
 -S: --save
 -D: --save-dev
 -O: --save-optional
The difference between devDependencies and dependencies is that the former contains
development tools, like a testing library, while the latter is bundled with the app in
production.
As for the optionalDependencies, the difference is that build failure of the dependency
will not cause the installation to fail. But it is your program's responsibility to handle the
lack of dependency. Read more about optional dependencies.
Updating packages
Updating is also made easy, by running
bash
npm update
npm will check all packages for a newer version that satisfies your versioning constraints.
You can specify a single package to update as well:
bash
npm update <package-name>
Versioning
In addition to plain downloads, npm also manages versioning, so you can specify any
specific version of a package, or require a version higher or lower than what you need.
Many times you'll find that a library is only compatible with a major release of another
library.
Or a bug in the latest release of a lib, still unfixed, is causing an issue.
Specifying an explicit version of a library also helps to keep everyone on the same
version of a package, so that the whole team runs the same version until
the package.json file is updated.
In all those cases, versioning helps a lot, and npm follows the semantic versioning
(semver) standard.
You can install a specific version of a package, by running
bash
npm install <package-name>@<version>
Running Tasks
The package.json file supports a format for specifying command-line tasks that can be
run by using
bash
npm run <task-name>
For example:
json
{
"scripts": {
"start-dev": "node lib/server-development",
"start": "node lib/server-production"
}
}
It's very common to use this feature to run Webpack:
json
{
"scripts": {
"watch": "webpack --watch --progress --colors --config
webpack.conf.js",
"dev": "webpack --progress --colors --config webpack.conf.js",
"prod": "NODE_ENV=production webpack -p --config webpack.conf.js"
}
}
So instead of typing those long commands, which are easy to forget or mistype, you can
run
bash
$ npm run watch
$ npm run dev
$ npm run prod

More Related Content

Similar to Node J pdf.docx

Basic Concept of Node.js & NPM
Basic Concept of Node.js & NPMBasic Concept of Node.js & NPM
Basic Concept of Node.js & NPMBhargav Anadkat
 
node_js.pptx
node_js.pptxnode_js.pptx
node_js.pptxdipen55
 
All You Need to Know About Using Node.pdf
All You Need to Know About Using Node.pdfAll You Need to Know About Using Node.pdf
All You Need to Know About Using Node.pdfiDataScientists
 
Kalp Corporate Node JS Perfect Guide
Kalp Corporate Node JS Perfect GuideKalp Corporate Node JS Perfect Guide
Kalp Corporate Node JS Perfect GuideKalp Corporate
 
Node.js and the MEAN Stack Building Full-Stack Web Applications.pdf
Node.js and the MEAN Stack Building Full-Stack Web Applications.pdfNode.js and the MEAN Stack Building Full-Stack Web Applications.pdf
Node.js and the MEAN Stack Building Full-Stack Web Applications.pdflubnayasminsebl
 
Node js installation steps.pptx slide share ppts
Node js installation steps.pptx slide share pptsNode js installation steps.pptx slide share ppts
Node js installation steps.pptx slide share pptsHemaSenthil5
 
The Positive and Negative Aspects of Node.js Web App Development.pdf
The Positive and Negative Aspects of Node.js Web App Development.pdfThe Positive and Negative Aspects of Node.js Web App Development.pdf
The Positive and Negative Aspects of Node.js Web App Development.pdfWDP Technologies
 
8 Node.js Frameworks Every Developer Should Know [UPDATED].pptx
8 Node.js Frameworks Every Developer Should Know [UPDATED].pptx8 Node.js Frameworks Every Developer Should Know [UPDATED].pptx
8 Node.js Frameworks Every Developer Should Know [UPDATED].pptx75waytechnologies
 
Node.js Development Tools
 Node.js Development Tools Node.js Development Tools
Node.js Development ToolsSofiaCarter4
 
Halton Software Peer 2 Peer Meetup #10
Halton Software Peer 2 Peer Meetup #10Halton Software Peer 2 Peer Meetup #10
Halton Software Peer 2 Peer Meetup #10David Ashton
 
Node.js Web Development.pdf
Node.js Web Development.pdfNode.js Web Development.pdf
Node.js Web Development.pdfSonia Simi
 
Don’t Let Your Businesses Get Hampered By Large Volume Codes: Nodejs Is Your ...
Don’t Let Your Businesses Get Hampered By Large Volume Codes: Nodejs Is Your ...Don’t Let Your Businesses Get Hampered By Large Volume Codes: Nodejs Is Your ...
Don’t Let Your Businesses Get Hampered By Large Volume Codes: Nodejs Is Your ...Techahead Software
 

Similar to Node J pdf.docx (20)

Node js
Node jsNode js
Node js
 
Node js Introduction
Node js IntroductionNode js Introduction
Node js Introduction
 
Basic Concept of Node.js & NPM
Basic Concept of Node.js & NPMBasic Concept of Node.js & NPM
Basic Concept of Node.js & NPM
 
node_js.pptx
node_js.pptxnode_js.pptx
node_js.pptx
 
Nodejs
NodejsNodejs
Nodejs
 
All You Need to Know About Using Node.pdf
All You Need to Know About Using Node.pdfAll You Need to Know About Using Node.pdf
All You Need to Know About Using Node.pdf
 
Kalp Corporate Node JS Perfect Guide
Kalp Corporate Node JS Perfect GuideKalp Corporate Node JS Perfect Guide
Kalp Corporate Node JS Perfect Guide
 
Node.js and the MEAN Stack Building Full-Stack Web Applications.pdf
Node.js and the MEAN Stack Building Full-Stack Web Applications.pdfNode.js and the MEAN Stack Building Full-Stack Web Applications.pdf
Node.js and the MEAN Stack Building Full-Stack Web Applications.pdf
 
node.js
node.jsnode.js
node.js
 
Node js installation steps.pptx slide share ppts
Node js installation steps.pptx slide share pptsNode js installation steps.pptx slide share ppts
Node js installation steps.pptx slide share ppts
 
Nodejs presentation
Nodejs presentationNodejs presentation
Nodejs presentation
 
The Positive and Negative Aspects of Node.js Web App Development.pdf
The Positive and Negative Aspects of Node.js Web App Development.pdfThe Positive and Negative Aspects of Node.js Web App Development.pdf
The Positive and Negative Aspects of Node.js Web App Development.pdf
 
8 Node.js Frameworks Every Developer Should Know [UPDATED].pptx
8 Node.js Frameworks Every Developer Should Know [UPDATED].pptx8 Node.js Frameworks Every Developer Should Know [UPDATED].pptx
8 Node.js Frameworks Every Developer Should Know [UPDATED].pptx
 
Node.js Development Tools
 Node.js Development Tools Node.js Development Tools
Node.js Development Tools
 
Proposal
ProposalProposal
Proposal
 
Halton Software Peer 2 Peer Meetup #10
Halton Software Peer 2 Peer Meetup #10Halton Software Peer 2 Peer Meetup #10
Halton Software Peer 2 Peer Meetup #10
 
02 Node introduction
02 Node introduction02 Node introduction
02 Node introduction
 
Node.js Web Development.pdf
Node.js Web Development.pdfNode.js Web Development.pdf
Node.js Web Development.pdf
 
Don’t Let Your Businesses Get Hampered By Large Volume Codes: Nodejs Is Your ...
Don’t Let Your Businesses Get Hampered By Large Volume Codes: Nodejs Is Your ...Don’t Let Your Businesses Get Hampered By Large Volume Codes: Nodejs Is Your ...
Don’t Let Your Businesses Get Hampered By Large Volume Codes: Nodejs Is Your ...
 
Reactjs Basics
Reactjs BasicsReactjs Basics
Reactjs Basics
 

More from PSK Technolgies Pvt. Ltd. IT Company Nagpur

More from PSK Technolgies Pvt. Ltd. IT Company Nagpur (18)

express.pdf
express.pdfexpress.pdf
express.pdf
 
express.pptx
express.pptxexpress.pptx
express.pptx
 
reatppt.pptx
reatppt.pptxreatppt.pptx
reatppt.pptx
 
Node J pdf.docx
Node J pdf.docxNode J pdf.docx
Node J pdf.docx
 
HTML.pptx
HTML.pptxHTML.pptx
HTML.pptx
 
REACT pdf.docx
REACT pdf.docxREACT pdf.docx
REACT pdf.docx
 
node js.pptx
node js.pptxnode js.pptx
node js.pptx
 
Low-Cost Digital Marketing Service in Nagpur | PSK Technologies
Low-Cost Digital Marketing Service in Nagpur | PSK TechnologiesLow-Cost Digital Marketing Service in Nagpur | PSK Technologies
Low-Cost Digital Marketing Service in Nagpur | PSK Technologies
 
Google Algorithm Updates
Google Algorithm UpdatesGoogle Algorithm Updates
Google Algorithm Updates
 
DIGITAL MARKETING.pptx
DIGITAL MARKETING.pptxDIGITAL MARKETING.pptx
DIGITAL MARKETING.pptx
 
Frontend Developer.pptx
Frontend Developer.pptxFrontend Developer.pptx
Frontend Developer.pptx
 
Content Marketing.pptx
Content Marketing.pptxContent Marketing.pptx
Content Marketing.pptx
 
What is Email Marketing ?
What is Email Marketing ?What is Email Marketing ?
What is Email Marketing ?
 
Importance of HTML
Importance of HTMLImportance of HTML
Importance of HTML
 
Core & Advance Java Training For Beginner-PSK Technologies Pvt. Ltd. Nagpur
Core & Advance Java Training For Beginner-PSK Technologies Pvt. Ltd. NagpurCore & Advance Java Training For Beginner-PSK Technologies Pvt. Ltd. Nagpur
Core & Advance Java Training For Beginner-PSK Technologies Pvt. Ltd. Nagpur
 
What is Java? Presentation On Introduction To Core Java By PSK Technologies
What is Java? Presentation On Introduction To Core Java By PSK TechnologiesWhat is Java? Presentation On Introduction To Core Java By PSK Technologies
What is Java? Presentation On Introduction To Core Java By PSK Technologies
 
Advance Networking Course Details PPT
Advance Networking Course Details PPTAdvance Networking Course Details PPT
Advance Networking Course Details PPT
 
What is c++ programming
What is c++ programmingWhat is c++ programming
What is c++ programming
 

Recently uploaded

Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsAndrey Dotsenko
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 

Node J pdf.docx

  • 1. Node JS Index  Introduction to Node.js  How to install Node.js  Differences between Node.js and the Browser  The V8 JavaScript Engine  An introduction to the NPM package manager  ECMAScript 2015 (ES6) and beyond
  • 2. Introduction to Node.js Node.js is an open-source and cross-platform JavaScript runtime environment. It is a popular tool for almost any kind of project! Node.js runs the V8 JavaScript engine, the core of Google Chrome, outside of the browser. This allows Node.js to be very performant. A Node.js app runs in a single process, without creating a new thread for every request. Node.js provides a set of asynchronous I/O primitives in its standard library that prevent JavaScript code from blocking and generally, libraries in Node.js are written using non- blocking paradigms, making blocking behavior the exception rather than the norm. When Node.js performs an I/O operation, like reading from the network, or accessing a database or the filesystem, instead of blocking the thread and wasting CPU cycles waiting, Node.js will resume the operations when the response comes back. This allows Node.js to handle thousands of concurrent connections with a single server without introducing the burden of managing thread concurrency, which could be a significant source of bugs. Node.js has a unique advantage because millions of frontend developers that write JavaScript for the browser can now write the server-side code in addition to the client- side code without needing to learn a completely different language. In Node.js the new ECMAScript standards can be used without problems, as you don't have to wait for all your users to update their browsers - you are in charge of deciding which ECMAScript version to use by changing the Node.js version, and you can also enable specific experimental features by running Node.js with flags. An Example Node.js Application The most common example Hello World of Node.js is a web server: js copy const http = require('HTTP); const hostname = '127.0.0.1'; const port = 3000; const server = http.createServer((req, res) => { res.statusCode = 200; res. set header('Content-Type', 'text/plain'); res.end('Hello Worldn');
  • 3. }); server.listen(port, hostname, () => { console.log(`Server running at http://${hostname}:${port}/`); }); To run this snippet, save it as a server.js file and run node server.js in your terminal. This code first includes the Node.js http module. Node.js has a fantastic standard library, including first-class support for networking. The createServer() method of HTTP creates a new HTTP server and returns it. The server is set to listen on the specified port and hostname. When the server is ready, the callback function is called, in this case informing us that the server is running. Whenever a new request is received, the request event is called, providing two objects: a request (an http.IncomingMessage object) and a response (an http.ServerResponse object). Those 2 objects are essential to handle the HTTP call. The first provides the requested details. In this simple example, this is not used, but you can access the request headers and request data. The second is used to return data to the caller. In this case with: js res.statusCode = 200; we set the statusCode property to 200, to indicate a successful response. We set the Content-Type header: js res.set header('Content-Type', 'text/plain'); and we close the response, adding the content as an argument to end(): js res.end('Hello Worldn'); How to install Node.js
  • 4. How to install Node.js Node.js can be installed in different ways. This post highlights the most common and convenient ones. Official packages for all the major platforms are available at https://nodejs.dev/download/. One very convenient way to install Node.js is through a package manager. In this case, every operating system has its own. Other package managers for MacOS, Linux, and Windows are listed at https://nodejs.dev/download/package-manager/ nvm is a popular way to run Node.js. It allows you to easily switch the Node.js version, and install new versions to try and easily roll back if something breaks. It is also very useful to test your code with old Node.js versions. See https://github.com/nvm-sh/nvm for more information about this option. In any case, when Node.js is installed you'll have access to the node executable program in the command line. Differences between Node.js and the Browser Both the browser and Node.js use JavaScript as their programming language. Building apps that run in the browser is a completely different thing than building a Node.js application. Even though it's always JavaScript, some key differences make the experience radically different. From the perspective of a frontend developer who extensively uses JavaScript, Node.js apps bring with them a huge advantage: the comfort of programming everything - the frontend and the backend - in a single language. You have a huge opportunity because we know how hard it is to fully, and deeply learn a programming language, and by using the same language to perform all your work on the web - both on the client and on the server, you're in a unique position of advantage. What changes is the ecosystem? In the browser, most of the time what you are doing is interacting with the DOM or other Web Platform APIs like Cookies. Those do not exist in Node.js, of course. You don't have the document, window a, nd all the other objects that are provided by the browser.
  • 5. And in the browser, we don't have all the nice APIs that Node.js provides through its modules, like the filesystem access functionality. Another big difference is that in Node.js you control the environment. Unless you are building an open-source application that anyone can deploy anywhere, you know which version of Node.js you will run the application on. Compared to the browser environment, where you don't get the luxury of choosing what browser your visitors will use, this is very convenient. This means that you can write all the modern ES2015+ JavaScript that your Node.js version supports. Since JavaScript moves so fast, but browsers can be a bit slow to upgrade, sometimes on the web you are stuck with using older JavaScript / ECMAScript releases. You can use Babel to transform your code to be ES5-compatible before shipping it to the browser, but in Node.js, you won't need that. Another difference is that Node.js supports both the CommonJS and ES module systems (since Node.js v12), while in the browser we are starting to see the ES Modules standard being implemented. In practice, this means that you can use both require() and import in Node.js, while you are limited to import in the browser. The V8 JavaScript Engine V8 is the name of the JavaScript engine that powers Google Chrome. It's the thing that takes our JavaScript and executes it while browsing with Chrome. V8 is the JavaScript engine i.e. it parses and executes JavaScript code. The DOM and the other Web Platform APIs (they all make up runtime environment) are provided by the browser. The cool thing is that the JavaScript engine is independent of the browser in which it's hosted. This key feature enabled the rise of Node.js. V8 was chosen to be the engine that powered Node.js back in 2009, and as the popularity of Node.js exploded, V8 became the engine that now powers an incredible amount of server-side code written in JavaScript. The Node.js ecosystem is huge and thanks to V8 which also powers desktop apps, with projects like Electron. Other JS engines Other browsers have their own JavaScript engine:
  • 6.  Firefox has SpiderMonkey  Safari has JavaScriptCore (also called Nitro)  Edge was originally based on Chakra but has more recently been rebuilt using Chromium and the V8 engine. and many others exist as well. All those engines implement the ECMA ES-262 standard, also called ECMAScript, the standard used by JavaScript. The quest for performance V8 is written in C++, and it's continuously improved. It is portable and runs on Mac, Windows, Linux, and several other systems. In this V8 introduction, we will ignore the implementation details of V8: they can be found on more authoritative sites (e.g. the V8 official site), and they change over time, often radically. V8 is always evolving, just like the other JavaScript engines around, to speed up the Web and the Node.js ecosystem. On the web, there is a race for performance that's been going on for years, and we (as users and developers) benefit a lot from this competition because we get faster and more optimized machines year after year. Compilation JavaScript is generally considered an interpreted language, but modern JavaScript engines no longer just interpret JavaScript, they compile it. This has been happening since 2009 when the SpiderMonkey JavaScript compiler was added to Firefox 3.5, and everyone followed this idea. JavaScript is internally compiled by V8 with just-in-time (JIT) compilation to speed up the execution. This might seem counter-intuitive, but since the introduction of Google Maps in 2004, JavaScript has evolved from a language that was generally executing a few dozens of lines of code to complete applications with thousands to hundreds of thousands of lines running in the browser. Our applications can now run for hours inside a browser, rather than being just a few form validation rules or simple scripts.
  • 7. ECMAScript 2015 (ES6) and beyond Node.js is built against modern versions of V8. By keeping up-to-date with the latest releases of this engine, we ensure new features from the JavaScript ECMA-262 specification are brought to Node.js developers promptly, as well as continued performance and stability improvements. All ECMAScript 2015 (ES6) features are split into three groups for shipping, staged, and in-progress features:  All shipping features, which V8 considers stable, are turned on by default on Node.js and do NOT require any kind of runtime flag.  Staged features, which are almost completed features that are not considered stable by the V8 team, require a runtime flag: --harmony.  In-progress features can be activated individually by their respective harmony flag, although this is highly discouraged unless for testing purposes. Note: These flags are exposed by V8 and will potentially change without any deprecation notice. Which features ship with which Node.js version by default? The website node. green provides an excellent overview of supported ECMAScript features in various versions of Node.js, based on Kangax's compat-table. Which features are in progress? New features are constantly being added to the V8 engine. Generally speaking, expect them to land on a future Node.js release, although the timing is unknown. You may list all the in-progress features available on each Node.js release by grepping through the --v8-options argument. Please note that these are incomplete and possibly broken features of V8, so use them at your own risk: bash copy node --v8-options | grep "in progress" I have my infrastructure set up to leverage the --harmony flag. Should I remove it? The current behavior of the --harmony flag on Node.js is to enable staged features only. After all, it is now a synonym of --es_staging. As mentioned above, these are completed features that have not been considered stable yet. If you want to play safe, especially in production environments, consider removing this runtime flag until it ships by default on V8 and, consequently, on Node.js. If you keep this enabled, you should be prepared for further Node.js upgrades to break your code if V8 changes its semantics to more closely follow the standard.
  • 8. How do I find which version of V8 ships with a particular version of Node.js? Node.js provides a simple way to list all dependencies and respective versions that ship with a specific binary through the process global object. In the case of the V8 engine, type the following in your terminal to retrieve its version: bash node -p process. versions.v8 An introduction to the NPM package manager Introduction to npm npm is the standard package manager for Node.js. In September 2022 over 2.1 million packages were reported to be listed in the npm registry, making it the biggest single language code repository on Earth, and you can be sure there is a package for (almost!) everything. It started as a way to download and manage dependencies of Node.js packages, but it has since become a tool used in frontend JavaScript. Yarn and ppm are alternatives to npm client. You can check them out as well. Packages npm manages downloads of dependencies of your project. Installing all dependencies If a project has a package.json file, by running bash npm install It will install everything the project needs, in the node_modules folder, creating it if it does not exist already. Installing a single package You can also install a specific package by running
  • 9. bash npm install <package-name> Furthermore, since npm 5, this command adds <package-name> to the package.json file dependencies. Before version 5, you needed to add the flag --save. Often you'll see more flags added to this command:  --save-dev installs and adds the entry to the package.json file devDependencies  --No-save installs but does not add the entry to the package.json file dependencies  --save-optional installs and adds the entry to the package.json file optional dependencies  --no-optional will prevent optional dependencies from being installed Shorthands of the flags can also be used:  -S: --save  -D: --save-dev  -O: --save-optional The difference between devDependencies and dependencies is that the former contains development tools, like a testing library, while the latter is bundled with the app in production. As for the optionalDependencies, the difference is that build failure of the dependency will not cause the installation to fail. But it is your program's responsibility to handle the lack of dependency. Read more about optional dependencies. Updating packages Updating is also made easy, by running bash npm update npm will check all packages for a newer version that satisfies your versioning constraints. You can specify a single package to update as well: bash npm update <package-name> Versioning In addition to plain downloads, npm also manages versioning, so you can specify any specific version of a package, or require a version higher or lower than what you need.
  • 10. Many times you'll find that a library is only compatible with a major release of another library. Or a bug in the latest release of a lib, still unfixed, is causing an issue. Specifying an explicit version of a library also helps to keep everyone on the same version of a package, so that the whole team runs the same version until the package.json file is updated. In all those cases, versioning helps a lot, and npm follows the semantic versioning (semver) standard. You can install a specific version of a package, by running bash npm install <package-name>@<version> Running Tasks The package.json file supports a format for specifying command-line tasks that can be run by using bash npm run <task-name> For example: json { "scripts": { "start-dev": "node lib/server-development", "start": "node lib/server-production" } } It's very common to use this feature to run Webpack: json { "scripts": { "watch": "webpack --watch --progress --colors --config webpack.conf.js", "dev": "webpack --progress --colors --config webpack.conf.js", "prod": "NODE_ENV=production webpack -p --config webpack.conf.js" } }
  • 11. So instead of typing those long commands, which are easy to forget or mistype, you can run bash $ npm run watch $ npm run dev $ npm run prod