SlideShare a Scribd company logo
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
Ad

More Related Content

Similar to Node J pdf.docx (20)

Node js Development Company - Aparajayah
Node js Development Company - AparajayahNode js Development Company - Aparajayah
Node js Development Company - Aparajayah
AparajayahTechnologi
 
Understanding Node.js and Django.docx
Understanding Node.js and Django.docxUnderstanding Node.js and Django.docx
Understanding Node.js and Django.docx
Savior_Marketing
 
Node.js and .NET Core.pdf
Node.js and .NET Core.pdfNode.js and .NET Core.pdf
Node.js and .NET Core.pdf
Appdeveloper10
 
Node js
Node jsNode js
Node js
Chirag Parmar
 
Node js Introduction
Node js IntroductionNode js Introduction
Node js Introduction
sanskriti agarwal
 
Basic Concept of Node.js & NPM
Basic Concept of Node.js & NPMBasic Concept of Node.js & NPM
Basic Concept of Node.js & NPM
Bhargav Anadkat
 
node_js.pptx
node_js.pptxnode_js.pptx
node_js.pptx
dipen55
 
Nodejs
NodejsNodejs
Nodejs
Bhushan Patil
 
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
iDataScientists
 
Kalp Corporate Node JS Perfect Guide
Kalp Corporate Node JS Perfect GuideKalp Corporate Node JS Perfect Guide
Kalp Corporate Node JS Perfect Guide
Kalp 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.pdf
lubnayasminsebl
 
node.js
node.jsnode.js
node.js
NepalAdz
 
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
HemaSenthil5
 
Nodejs presentation
Nodejs presentationNodejs presentation
Nodejs presentation
Arvind Devaraj
 
module for backend full stack applications 1.pptx
module for backend full stack applications 1.pptxmodule for backend full stack applications 1.pptx
module for backend full stack applications 1.pptx
hemalathas752360
 
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
WDP 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].pptx
75waytechnologies
 
Deno vs Node.js: A Comprehensive Comparison.docx
Deno vs Node.js: A Comprehensive Comparison.docxDeno vs Node.js: A Comprehensive Comparison.docx
Deno vs Node.js: A Comprehensive Comparison.docx
Vignesh Nethaji
 
Node.js Development Tools
 Node.js Development Tools Node.js Development Tools
Node.js Development Tools
SofiaCarter4
 
Proposal
ProposalProposal
Proposal
Constantine Priemski
 
Node js Development Company - Aparajayah
Node js Development Company - AparajayahNode js Development Company - Aparajayah
Node js Development Company - Aparajayah
AparajayahTechnologi
 
Understanding Node.js and Django.docx
Understanding Node.js and Django.docxUnderstanding Node.js and Django.docx
Understanding Node.js and Django.docx
Savior_Marketing
 
Node.js and .NET Core.pdf
Node.js and .NET Core.pdfNode.js and .NET Core.pdf
Node.js and .NET Core.pdf
Appdeveloper10
 
Basic Concept of Node.js & NPM
Basic Concept of Node.js & NPMBasic Concept of Node.js & NPM
Basic Concept of Node.js & NPM
Bhargav Anadkat
 
node_js.pptx
node_js.pptxnode_js.pptx
node_js.pptx
dipen55
 
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
iDataScientists
 
Kalp Corporate Node JS Perfect Guide
Kalp Corporate Node JS Perfect GuideKalp Corporate Node JS Perfect Guide
Kalp Corporate Node JS Perfect Guide
Kalp 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.pdf
lubnayasminsebl
 
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
HemaSenthil5
 
module for backend full stack applications 1.pptx
module for backend full stack applications 1.pptxmodule for backend full stack applications 1.pptx
module for backend full stack applications 1.pptx
hemalathas752360
 
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
WDP 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].pptx
75waytechnologies
 
Deno vs Node.js: A Comprehensive Comparison.docx
Deno vs Node.js: A Comprehensive Comparison.docxDeno vs Node.js: A Comprehensive Comparison.docx
Deno vs Node.js: A Comprehensive Comparison.docx
Vignesh Nethaji
 
Node.js Development Tools
 Node.js Development Tools Node.js Development Tools
Node.js Development Tools
SofiaCarter4
 

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

express.pdf
express.pdfexpress.pdf
express.pdf
PSK Technolgies Pvt. Ltd. IT Company Nagpur
 
express.pptx
express.pptxexpress.pptx
express.pptx
PSK Technolgies Pvt. Ltd. IT Company Nagpur
 
Node J pdf.docx
Node J pdf.docxNode J pdf.docx
Node J pdf.docx
PSK Technolgies Pvt. Ltd. IT Company Nagpur
 
reatppt.pptx
reatppt.pptxreatppt.pptx
reatppt.pptx
PSK Technolgies Pvt. Ltd. IT Company Nagpur
 
HTML.pptx
HTML.pptxHTML.pptx
HTML.pptx
PSK Technolgies Pvt. Ltd. IT Company Nagpur
 
REACT pdf.docx
REACT pdf.docxREACT pdf.docx
REACT pdf.docx
PSK Technolgies Pvt. Ltd. IT Company Nagpur
 
node js.pptx
node js.pptxnode js.pptx
node js.pptx
PSK Technolgies Pvt. Ltd. IT Company Nagpur
 
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
PSK Technolgies Pvt. Ltd. IT Company Nagpur
 
Google Algorithm Updates
Google Algorithm UpdatesGoogle Algorithm Updates
Google Algorithm Updates
PSK Technolgies Pvt. Ltd. IT Company Nagpur
 
DIGITAL MARKETING.pptx
DIGITAL MARKETING.pptxDIGITAL MARKETING.pptx
DIGITAL MARKETING.pptx
PSK Technolgies Pvt. Ltd. IT Company Nagpur
 
Frontend Developer.pptx
Frontend Developer.pptxFrontend Developer.pptx
Frontend Developer.pptx
PSK Technolgies Pvt. Ltd. IT Company Nagpur
 
Content Marketing.pptx
Content Marketing.pptxContent Marketing.pptx
Content Marketing.pptx
PSK Technolgies Pvt. Ltd. IT Company Nagpur
 
What is Email Marketing ?
What is Email Marketing ?What is Email Marketing ?
What is Email Marketing ?
PSK Technolgies Pvt. Ltd. IT Company Nagpur
 
Importance of HTML
Importance of HTMLImportance of HTML
Importance of HTML
PSK Technolgies Pvt. Ltd. IT Company Nagpur
 
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
PSK Technolgies Pvt. Ltd. IT Company 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
PSK Technolgies Pvt. Ltd. IT Company Nagpur
 
Advance Networking Course Details PPT
Advance Networking Course Details PPTAdvance Networking Course Details PPT
Advance Networking Course Details PPT
PSK Technolgies Pvt. Ltd. IT Company Nagpur
 
What is c++ programming
What is c++ programmingWhat is c++ programming
What is c++ programming
PSK Technolgies Pvt. Ltd. IT Company Nagpur
 
Ad

Recently uploaded (20)

Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Ad

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