Node.js is an event-driven JavaScript runtime built on Chrome's V8 engine. It uses non-blocking I/O and an event loop to handle multiple connections simultaneously without blocking. The document discusses Node.js' event loop model and asynchronous I/O, how callbacks allow non-blocking operations, and how modules and frameworks like Express allow building scalable network applications.
Its a presentation about node.js. Here I have covered the basic things of node.js. Like what is node.js how it can be used. and explanation about some node.js frameworks
Understanding the Single Thread Event LoopTorontoNodeJS
Node JS was built on Google's JavaScript V8 Engine and it was engineered to preform optimally for the web. Learn what Node JS's single thread event loop is and how it empowers Node to out preform its competitors.
“Node's goal is to provide an easy way to build scalable Network programs”
Asynchronous i/o framework
Core in c++ on top of v8
Rest of it in javascript
Swiss army knife for network Related stuffs
Can handle thousands of Concurrent connections with Minimal overhead (cpu/memory) on a single process
It’s NOT a web framework, and it’s also NOT a language
• Created by Ryan Dahl in 2009
• Development && maintenance sponsored by Joyent
• License MIT
• Last release : 0.10.31
• Based on Google V8 Engine
• +99 000 packages
An absolute beginners guide to node.js . Done for a presentation at college. The presentation contains data from various sources ,sources are noted at the end slide. please inform me any mistakes ,since at that time i was in a bit of hurry :)
Its a presentation about node.js. Here I have covered the basic things of node.js. Like what is node.js how it can be used. and explanation about some node.js frameworks
Understanding the Single Thread Event LoopTorontoNodeJS
Node JS was built on Google's JavaScript V8 Engine and it was engineered to preform optimally for the web. Learn what Node JS's single thread event loop is and how it empowers Node to out preform its competitors.
“Node's goal is to provide an easy way to build scalable Network programs”
Asynchronous i/o framework
Core in c++ on top of v8
Rest of it in javascript
Swiss army knife for network Related stuffs
Can handle thousands of Concurrent connections with Minimal overhead (cpu/memory) on a single process
It’s NOT a web framework, and it’s also NOT a language
• Created by Ryan Dahl in 2009
• Development && maintenance sponsored by Joyent
• License MIT
• Last release : 0.10.31
• Based on Google V8 Engine
• +99 000 packages
An absolute beginners guide to node.js . Done for a presentation at college. The presentation contains data from various sources ,sources are noted at the end slide. please inform me any mistakes ,since at that time i was in a bit of hurry :)
Introduction to node js - From "hello world" to deploying on azureColin Mackay
Slide deck from my talk on Node.js.
More information is available here: http://colinmackay.scot/2014/11/29/dunddd-2014-introduction-to-node-jsfrom-hello-world-to-deploying-on-azure/
These are the slides that were used for my presentation on Node.js in OpenSlava 2013 (October 11th, 2013, Bratislava) and provide an introduction to Node.js as well as analyze the potential effects of introducing Node.js in an enterprise and from an architectural perspective.
Nodejs Event Driven Concurrency for Web ApplicationsGanesh Iyer
We describe the event-driven concurrency model used by Nodejs, a JavaScript server-side scripting platform. An overview of the traditional thread based approach(used by Apache) is also given. We compare both the approaches. An Introduction to Nodejs programming is provided and some useful packages are discussed.
Slides from my workshop about node.js which I conducted in Girl Geek Dinner Bangalore. More details at http://sudarmuthu.com/blog/introduction-to-node-js-at-yahoo-girl-geek-dinner
What is Node.js | Node.js Tutorial for Beginners | Node.js Modules | Node.js ...Edureka!
This Edureka "What is Node.js" tutorial will help you to learn the Node.js fundamentals and how to create an application in Node.js. Node.js is an open-source, cross-platform JavaScript runtime environment for developing a diverse variety of server tools and applications. Below are the topics covered in this tutorial:
1) Client Server Architecture
2) Limitations of Multi – Threaded Model
3) What is Node.js?
4) Features of Node.js
5) Node.js Installation
6) Blocking Vs. Non – Blocking I/O
7) Creating Node.js Program
8) Node.js Modules
Introduction to node js - From "hello world" to deploying on azureColin Mackay
Slide deck from my talk on Node.js.
More information is available here: http://colinmackay.scot/2014/11/29/dunddd-2014-introduction-to-node-jsfrom-hello-world-to-deploying-on-azure/
These are the slides that were used for my presentation on Node.js in OpenSlava 2013 (October 11th, 2013, Bratislava) and provide an introduction to Node.js as well as analyze the potential effects of introducing Node.js in an enterprise and from an architectural perspective.
Nodejs Event Driven Concurrency for Web ApplicationsGanesh Iyer
We describe the event-driven concurrency model used by Nodejs, a JavaScript server-side scripting platform. An overview of the traditional thread based approach(used by Apache) is also given. We compare both the approaches. An Introduction to Nodejs programming is provided and some useful packages are discussed.
Slides from my workshop about node.js which I conducted in Girl Geek Dinner Bangalore. More details at http://sudarmuthu.com/blog/introduction-to-node-js-at-yahoo-girl-geek-dinner
What is Node.js | Node.js Tutorial for Beginners | Node.js Modules | Node.js ...Edureka!
This Edureka "What is Node.js" tutorial will help you to learn the Node.js fundamentals and how to create an application in Node.js. Node.js is an open-source, cross-platform JavaScript runtime environment for developing a diverse variety of server tools and applications. Below are the topics covered in this tutorial:
1) Client Server Architecture
2) Limitations of Multi – Threaded Model
3) What is Node.js?
4) Features of Node.js
5) Node.js Installation
6) Blocking Vs. Non – Blocking I/O
7) Creating Node.js Program
8) Node.js Modules
Node.js 101 with Rami Sayar
Presented on September 18 2014 at
FITC's Web Unleashed Toronto 2014 Conference
More info at www.fitc.ca
OVERVIEW
Node.js is a runtime environment and library for running JavaScript applications outside the browser. Node.js is mostly used to run real-time server applications and shines through its performance using non-blocking I/O and asynchronous events. This talk will introduce you to Node.js by showcasing the environment and its two most popular libraries: express and socket.io.
TARGET AUDIENCE
Beginner web developers
ASSUMED AUDIENCE KNOWLEDGE
Working knowledge of JavaScript and HTML5.
OBJECTIVE
Learn how to build a chat engine using Node.js and WebSockets.
FIVE THINGS AUDIENCE MEMBERS WILL LEARN
Node.js environment and basics
Node Package Manager overview
Web Framework, express, basics
WebSockets and Socket.io basics
Building a chat engine using Node.js
Save 10% off ANY FITC event with discount code 'slideshare' - http://www.fitc.ca
OVERVIEW
Node.js is a runtime environment and library for running JavaScript applications outside the browser. Node.js is mostly used to run real-time server applications and shines through its performance using non-blocking I/O and asynchronous events. This talk will introduce you to Node.js by showcasing the environment and its two most popular libraries: express and socket.io.
TARGET AUDIENCE
Beginner web developers
ASSUMED AUDIENCE KNOWLEDGE
Working knowledge of JavaScript and HTML5.
OBJECTIVE
Learn how to build a chat engine using Node.js and WebSockets.
FIVE THINGS AUDIENCE MEMBERS WILL LEARN
Node.js environment and basics
Node Package Manager overview
Web Framework, express, basics
WebSockets and Socket.io basics
Building a chat engine using Node.js
These are the slides to a talk I gave at Pittsburgh techFest 2012. The topic was an overview of the Node.js framework, and how you can use it to build amazing things.
* See more of my work at http://www.codehenge.net
This is a presentation I prepared for a local meetup. The audience is a mix of web designers and developers who have a wide range of development experience.
Save 10% off ANY FITC event with discount code 'slideshare'
See our upcoming events at www.fitc.ca
Node.js: The What, The How and The When
with Richard Nieuwenhuis
I'm talking about how Ansible helps Backbase establish testing pipeline to ensure the quality of Customer Experience Platform - the leading horizontal portal software. This is done by utilizing the concept of immutable infrastructure to provision on-demand infrastructure use it and the dispose.
Node.js® is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.
Introducing Node.js in an Oracle technology environment (including hands-on)Lucas Jellema
This presentation introduces Node.js in a few simple, straightforward steps. First, Node.js is presented as just JavaScript on the browser, then HTTP handling is discussed with core module http and subsequently using Express. Running Oracle JET from Node.js is explained. The implementation of APIs - REST services supporting various [operations on] resources is discussed. The single-thread nature of Node.js is presented, along with the essentials of asynchrous programming, working with callbacks and using the async module. The Node Oracle DB Database driver is introduced and demonstrated. Finally, further steps are suggested. This presentation is supported by a set of resources that constitute a three hour hands on session - sources are in GitHub https://github.com/lucasjellema/sig-nodejs-amis-2016.
Graspan: A Big Data System for Big Code AnalysisAftab Hussain
We built a disk-based parallel graph system, Graspan, that uses a novel edge-pair centric computation model to compute dynamic transitive closures on very large program graphs.
We implement context-sensitive pointer/alias and dataflow analyses on Graspan. An evaluation of these analyses on large codebases such as Linux shows that their Graspan implementations scale to millions of lines of code and are much simpler than their original implementations.
These analyses were used to augment the existing checkers; these augmented checkers found 132 new NULL pointer bugs and 1308 unnecessary NULL tests in Linux 4.4.0-rc5, PostgreSQL 8.3.9, and Apache httpd 2.2.18.
- Accepted in ASPLOS ‘17, Xi’an, China.
- Featured in the tutorial, Systemized Program Analyses: A Big Data Perspective on Static Analysis Scalability, ASPLOS ‘17.
- Invited for presentation at SoCal PLS ‘16.
- Invited for poster presentation at PLDI SRC ‘16.
Quarkus Hidden and Forbidden ExtensionsMax Andersen
Quarkus has a vast extension ecosystem and is known for its subsonic and subatomic feature set. Some of these features are not as well known, and some extensions are less talked about, but that does not make them less interesting - quite the opposite.
Come join this talk to see some tips and tricks for using Quarkus and some of the lesser known features, extensions and development techniques.
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Mind IT Systems
Healthcare providers often struggle with the complexities of chronic conditions and remote patient monitoring, as each patient requires personalized care and ongoing monitoring. Off-the-shelf solutions may not meet these diverse needs, leading to inefficiencies and gaps in care. It’s here, custom healthcare software offers a tailored solution, ensuring improved care and effectiveness.
Utilocate offers a comprehensive solution for locate ticket management by automating and streamlining the entire process. By integrating with Geospatial Information Systems (GIS), it provides accurate mapping and visualization of utility locations, enhancing decision-making and reducing the risk of errors. The system's advanced data analytics tools help identify trends, predict potential issues, and optimize resource allocation, making the locate ticket management process smarter and more efficient. Additionally, automated ticket management ensures consistency and reduces human error, while real-time notifications keep all relevant personnel informed and ready to respond promptly.
The system's ability to streamline workflows and automate ticket routing significantly reduces the time taken to process each ticket, making the process faster and more efficient. Mobile access allows field technicians to update ticket information on the go, ensuring that the latest information is always available and accelerating the locate process. Overall, Utilocate not only enhances the efficiency and accuracy of locate ticket management but also improves safety by minimizing the risk of utility damage through precise and timely locates.
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxrickgrimesss22
Discover the essential features to incorporate in your Winzo clone app to boost business growth, enhance user engagement, and drive revenue. Learn how to create a compelling gaming experience that stands out in the competitive market.
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeAftab Hussain
Understanding variable roles in code has been found to be helpful by students
in learning programming -- could variable roles help deep neural models in
performing coding tasks? We do an exploratory study.
- These are slides of the talk given at InteNSE'23: The 1st International Workshop on Interpretability and Robustness in Neural Software Engineering, co-located with the 45th International Conference on Software Engineering, ICSE 2023, Melbourne Australia
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Crescat
Crescat is industry-trusted event management software, built by event professionals for event professionals. Founded in 2017, we have three key products tailored for the live event industry.
Crescat Event for concert promoters and event agencies. Crescat Venue for music venues, conference centers, wedding venues, concert halls and more. And Crescat Festival for festivals, conferences and complex events.
With a wide range of popular features such as event scheduling, shift management, volunteer and crew coordination, artist booking and much more, Crescat is designed for customisation and ease-of-use.
Over 125,000 events have been planned in Crescat and with hundreds of customers of all shapes and sizes, from boutique event agencies through to international concert promoters, Crescat is rigged for success. What's more, we highly value feedback from our users and we are constantly improving our software with updates, new features and improvements.
If you plan events, run a venue or produce festivals and you're looking for ways to make your life easier, then we have a solution for you. Try our software for free or schedule a no-obligation demo with one of our product specialists today at crescat.io
Enterprise Resource Planning System includes various modules that reduce any business's workload. Additionally, it organizes the workflows, which drives towards enhancing productivity. Here are a detailed explanation of the ERP modules. Going through the points will help you understand how the software is changing the work dynamics.
To know more details here: https://blogs.nyggs.com/nyggs/enterprise-resource-planning-erp-system-modules/
Launch Your Streaming Platforms in MinutesRoshan Dwivedi
The claim of launching a streaming platform in minutes might be a bit of an exaggeration, but there are services that can significantly streamline the process. Here's a breakdown:
Pros of Speedy Streaming Platform Launch Services:
No coding required: These services often use drag-and-drop interfaces or pre-built templates, eliminating the need for programming knowledge.
Faster setup: Compared to building from scratch, these platforms can get you up and running much quicker.
All-in-one solutions: Many services offer features like content management systems (CMS), video players, and monetization tools, reducing the need for multiple integrations.
Things to Consider:
Limited customization: These platforms may offer less flexibility in design and functionality compared to custom-built solutions.
Scalability: As your audience grows, you might need to upgrade to a more robust platform or encounter limitations with the "quick launch" option.
Features: Carefully evaluate which features are included and if they meet your specific needs (e.g., live streaming, subscription options).
Examples of Services for Launching Streaming Platforms:
Muvi [muvi com]
Uscreen [usencreen tv]
Alternatives to Consider:
Existing Streaming platforms: Platforms like YouTube or Twitch might be suitable for basic streaming needs, though monetization options might be limited.
Custom Development: While more time-consuming, custom development offers the most control and flexibility for your platform.
Overall, launching a streaming platform in minutes might not be entirely realistic, but these services can significantly speed up the process compared to building from scratch. Carefully consider your needs and budget when choosing the best option for you.
OpenMetadata Community Meeting - 5th June 2024OpenMetadata
The OpenMetadata Community Meeting was held on June 5th, 2024. In this meeting, we discussed about the data quality capabilities that are integrated with the Incident Manager, providing a complete solution to handle your data observability needs. Watch the end-to-end demo of the data quality features.
* How to run your own data quality framework
* What is the performance impact of running data quality frameworks
* How to run the test cases in your own ETL pipelines
* How the Incident Manager is integrated
* Get notified with alerts when test cases fail
Watch the meeting recording here - https://www.youtube.com/watch?v=UbNOje0kf6E
GraphSummit Paris - The art of the possible with Graph TechnologyNeo4j
Sudhir Hasbe, Chief Product Officer, Neo4j
Join us as we explore breakthrough innovations enabled by interconnected data and AI. Discover firsthand how organizations use relationships in data to uncover contextual insights and solve our most pressing challenges – from optimizing supply chains, detecting fraud, and improving customer experiences to accelerating drug discoveries.
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Łukasz Chruściel
No one wants their application to drag like a car stuck in the slow lane! Yet it’s all too common to encounter bumpy, pothole-filled solutions that slow the speed of any application. Symfony apps are not an exception.
In this talk, I will take you for a spin around the performance racetrack. We’ll explore common pitfalls - those hidden potholes on your application that can cause unexpected slowdowns. Learn how to spot these performance bumps early, and more importantly, how to navigate around them to keep your application running at top speed.
We will focus in particular on tuning your engine at the application level, making the right adjustments to ensure that your system responds like a well-oiled, high-performance race car.
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppGoogle
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
👉👉 Click Here To Get More Info 👇👇
https://sumonreview.com/ai-fusion-buddy-review
AI Fusion Buddy Review: Key Features
✅Create Stunning AI App Suite Fully Powered By Google's Latest AI technology, Gemini
✅Use Gemini to Build high-converting Converting Sales Video Scripts, ad copies, Trending Articles, blogs, etc.100% unique!
✅Create Ultra-HD graphics with a single keyword or phrase that commands 10x eyeballs!
✅Fully automated AI articles bulk generation!
✅Auto-post or schedule stunning AI content across all your accounts at once—WordPress, Facebook, LinkedIn, Blogger, and more.
✅With one keyword or URL, generate complete websites, landing pages, and more…
✅Automatically create & sell AI content, graphics, websites, landing pages, & all that gets you paid non-stop 24*7.
✅Pre-built High-Converting 100+ website Templates and 2000+ graphic templates logos, banners, and thumbnail images in Trending Niches.
✅Say goodbye to wasting time logging into multiple Chat GPT & AI Apps once & for all!
✅Save over $5000 per year and kick out dependency on third parties completely!
✅Brand New App: Not available anywhere else!
✅ Beginner-friendly!
✅ZERO upfront cost or any extra expenses
✅Risk-Free: 30-Day Money-Back Guarantee!
✅Commercial License included!
See My Other Reviews Article:
(1) AI Genie Review: https://sumonreview.com/ai-genie-review
(2) SocioWave Review: https://sumonreview.com/sociowave-review
(3) AI Partner & Profit Review: https://sumonreview.com/ai-partner-profit-review
(4) AI Ebook Suite Review: https://sumonreview.com/ai-ebook-suite-review
#AIFusionBuddyReview,
#AIFusionBuddyFeatures,
#AIFusionBuddyPricing,
#AIFusionBuddyProsandCons,
#AIFusionBuddyTutorial,
#AIFusionBuddyUserExperience
#AIFusionBuddyforBeginners,
#AIFusionBuddyBenefits,
#AIFusionBuddyComparison,
#AIFusionBuddyInstallation,
#AIFusionBuddyRefundPolicy,
#AIFusionBuddyDemo,
#AIFusionBuddyMaintenanceFees,
#AIFusionBuddyNewbieFriendly,
#WhatIsAIFusionBuddy?,
#HowDoesAIFusionBuddyWorks
AI Genie Review: World’s First Open AI WordPress Website CreatorGoogle
AI Genie Review: World’s First Open AI WordPress Website Creator
👉👉 Click Here To Get More Info 👇👇
https://sumonreview.com/ai-genie-review
AI Genie Review: Key Features
✅Creates Limitless Real-Time Unique Content, auto-publishing Posts, Pages & Images directly from Chat GPT & Open AI on WordPress in any Niche
✅First & Only Google Bard Approved Software That Publishes 100% Original, SEO Friendly Content using Open AI
✅Publish Automated Posts and Pages using AI Genie directly on Your website
✅50 DFY Websites Included Without Adding Any Images, Content Or Doing Anything Yourself
✅Integrated Chat GPT Bot gives Instant Answers on Your Website to Visitors
✅Just Enter the title, and your Content for Pages and Posts will be ready on your website
✅Automatically insert visually appealing images into posts based on keywords and titles.
✅Choose the temperature of the content and control its randomness.
✅Control the length of the content to be generated.
✅Never Worry About Paying Huge Money Monthly To Top Content Creation Platforms
✅100% Easy-to-Use, Newbie-Friendly Technology
✅30-Days Money-Back Guarantee
See My Other Reviews Article:
(1) TubeTrivia AI Review: https://sumonreview.com/tubetrivia-ai-review
(2) SocioWave Review: https://sumonreview.com/sociowave-review
(3) AI Partner & Profit Review: https://sumonreview.com/ai-partner-profit-review
(4) AI Ebook Suite Review: https://sumonreview.com/ai-ebook-suite-review
#AIGenieApp #AIGenieBonus #AIGenieBonuses #AIGenieDemo #AIGenieDownload #AIGenieLegit #AIGenieLiveDemo #AIGenieOTO #AIGeniePreview #AIGenieReview #AIGenieReviewandBonus #AIGenieScamorLegit #AIGenieSoftware #AIGenieUpgrades #AIGenieUpsells #HowDoesAlGenie #HowtoBuyAIGenie #HowtoMakeMoneywithAIGenie #MakeMoneyOnline #MakeMoneywithAIGenie
3. Review of Node.js
• A platform built on Chrome’s JavaScript runtime for easily building
fast, scalable network applications.
• Uses an event-driven, non-blocking I/O model that makes it
lightweight and efficient
• Perfect for data-intensive real-time applications that run across
distributed devices
• Contains a built-in HTTP server library
• Making it possible to run a web server without the use of external
software, such as Apache or Lighttpd
• Allowing more control of how the web server works
4. Review of Node.js
• Feature of Node.js
• V8 JavaScript Engine
• Single-threaded
• Event-driven
• Non-blocking I/O model
6. Event Loop – Basic Thesis
• The first basic thesis of node.js is that I/O is expensive
• So the largest waste with current programming technologies comes
from waiting for I/O to complete.
7. Event Loop – Basic Thesis
• There are several ways in which one can deal with the performance
impact
• Synchronous
• you handle one request at a time, each in turn.
• fork a new process:
• you start a new process to handle each request.
• threads:
• start a new thread to handle each request.
8. Event Loop – Basic Thesis
• The second basis thesis is that thread-per-connection is memory-
expensive
• Apache is multithreaded. It spawns a thread per request (or process,
it depends on the conf).
• Node.js is not multithreaded, because threads and processes carry a
heavy memory cost.
11. Event Loop – Callback
• An event loop is “an entity that handles and processes external
events and converts them into callback invocations”.
• At an I/O call, your code saves the callback and returns control to the
node.js runtime environment.
• The callback will be called later when the data actually is available.
12. Event Loop – Callback
• First-class functions
• E.g. we pass around functions as data, shuffle them around and execute them
when needed.
• Function composition
• Also known as having anonymous functions or closures that are executed
after something happens in the evented I/O.
function say(word) {
console.log(word);
}
function execute(someFunction, value) {
someFunction(value);
}
execute(say, "Hello");
function execute(someFunction, value) {
someFunction(value);
}
execute(function(word){ console.log(word) }, "Hello");
13. Event Loop – Callback
• Run the node.js app, it will immediately output “Server has started”
• When sending request to server, “Request received” is shown
• This is an event-driven
asynchronous server-side
JavaScript and its callback
var http = require("http");
function onRequest(request, response) {
console.log("Request received.");
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}
http.createServer(onRequest).listen(8888);
console.log("Server has started.");
14. Event Loop – Asynchronous Mechanism
• Node.js is event-driven design
• In web application, it is said to have the fastest real-time response
• The principle is to use libuv to implement event polling, constantly
check for events that need to be processed
• If it finds an event on standby, run and trigger the corresponding
handler.
15. Event Loop – Asynchronous Mechanism
• Node.js keeps a single thread for your code
• Doing a “sleep” will block the server
• So while that code is running, node.js will not respond to any other
requests from clients, since it only has one thread for executing your
code.
• Or if you would have some CPU -intensive code, say, for resizing
images, that would still block all other requests.
16. Event Loop – Asynchronous Mechanism
• The console will shown
“blah…” after the file
is read
file.open();
while(true) {
result = file.read();
if (!result)
break;
/* Do something... */
}
console.log('blah blah blah...');
Difficult task
Easy task
Difficult task
done on time
Easy task
delayed
17. Event Loop – Asynchronous Mechanism
• process.nextTick(callback)
• On the next loop around the event loop call this callback.
• This is not a simple alias to setTimeout(fn, 0), it's much more efficient. It
typically runs before any other I/O events fires
• Node.js implements a queue storing events
• All event triggers are driven by the engine of a polling event.
• process.nextTick () is that we can put a program into the event queue,
the next time the event polling is driven.
18. Event Loop – Asynchronous Mechanism
Difficult task
Easy task
Easy task done.
Strill delayed
difficult task
done
function readLoop() {
result = file.read();
if (!result)
return;
/* Do something... */
process.nextTick(readLoop);
}
file.open();
process.nextTick(readLoop);
console.log('blah blah blah...');
19. Event Loop – Asynchronous Mechanism
• child_process.fork
• Spawn Node processes
• Having all the methods in a normal ChildProcess instance, the returned object
has a communication channel built-in.
• Assume at least 30ms startup and 10mb memory for each new Node. That is,
you cannot create many thousands of them.
21. Event Loop – Asynchronous Mechanism
• Cluster
• A single instance of Node runs in a single thread.
• To take advantage of multi-core systems the user will sometimes want to
launch a cluster of Node processes to handle the load.
• The cluster module allows you to easily create child processes that all share
server ports.
22. Event Loop – Asynchronous Mechanism
var cluster = require('cluster');
var http = require('http');
var numCPUs = require('os').cpus().length;
if (cluster.isMaster) { // Fork workers.
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}
cluster.on('exit', function(worker, code, signal) {
console.log('worker ' +
worker.process.pid + ' died');
});
} else { // Workers can share any TCP connection
// In this case its a HTTP server
http.createServer(function(req, res) {
res.writeHead(200);
res.end("hello worldn");
}).listen(8000);
}
Difficult task
Easy task 1
Easy task 2
Easy task 1 done
v
Easy task 2 done
difficult task
done
24. Module
• NPM(Node Package Manager)
• The official package manager for Node.js.
• As of Node.js version 0.6.3, npm is bundled and installed automatically with
the environment.
• Runs through the command line and manages dependencies for an
application.
• Allows users to install Node.js applications that are available on the npm
registry.
• Written entirely in JavaScript, and runs on the Node.js platform.
25. Module
• We use require and exports to connect with module
var http = require("http");
function start() {
function onRequest(request, response) {
console.log("Request received.");
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}
http.createServer(onRequest).listen(8888);
console.log("Server has started.");
}
exports.start = start;
Module can be download with npm
var server = require("./server");
server.start();
Module can be written by requirements
server.js index.js
26. Express
• Express is a minimal and flexible node.js web application framework
• Providing a robust set of features for building single and multi-page,
and hybrid web applications.
27. Express
• >npm info express version
• edit package.json
• >npm install
{
"name": "hello-world",
"description": "hello world test app",
"version": "0.0.1",
"private": true,
"dependencies": {
"express": "4.0.0"
}
}
28. Express
• Node.js has more and more resources related to development,
• No need to write many features, you can directly use the module has
been developed via official NPM tool from the others on the network
• Developers can focus wholeheartedly on the current development of
applications.
• We always depend on a lot of third-party modules, and whenever we
change the develop environment, it is necessary manually installing
modules
• package.json file directly manage project dependencies and
modules which being used by project
29. Express
• Three outstanding features
• routing distribution
• request processing
• rendering the view
var app = express();
app.get("/hello/:who", function(req, res) {
res.end("Hello, " + req.params.who + ".");
});
// 啓動Express
var express = require("express");
var app = express();
// 設置view目錄
app.set("views", __dirname + "/views");
// 設置模板引擎
app.set("view engine", "jade");
30. Conclusion
• Web applications typically have bottleneck in I/O of network, and
Node.js solves them well.
• Node.js uses JavaScript, which web developers already familiar with.
• NPM let everyone easily put theirs modules on.
• The disadvantage is that Node.js is new, not stable enough, API
regularly updated.