SlideServe
Menu
Préférences
© SlideServe · v2026

Node.js - What is Node.js? -

yoshio-mosley avatar
14 diapositives · 553 Views · Nov 03, 2014

Node.js - What is Node.js? -. Sep. 2014 Youn-Hee Han http://link.koreatech.ac.kr. What is Node.js?. A JavaScript runtime environment running Google Chrome’s V8 engine a.k.a. a server-side solution for JS Runs over the command line Designed for high concurrency

Node.js - What is Node.js? - - slide 1
01 / 14Node.js - What is Node.js? -
1 / 17

Télécharger la présentation

Node.js - What is Node.js? -
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Node.js- What is Node.js? - Sep. 2014 Youn-Hee Han http://link.koreatech.ac.kr

  2. What is Node.js? • A JavaScript runtime environment running Google Chrome’s V8 engine • a.k.a. a server-side solution for JS • Runs over the command line • Designed for high concurrency • Without threads or new processes • Making it really fast • Never blocks, not even for I/O • Created by Ryan Dahl starting in 2009 • Node.js is a platform (is not a framework) • Express is a framework for Node.js • http://sbrich.tistory.com/395참고

  3. What is Node.js? • Goal is to provide an easy way to build scalable network programs. • It makes communication between client and server happen in same language (JavaScript) • Node is a platform for writing JavaScript applications outside web browsers. • There is no DOM built into Node, nor any other browser capability. • Node is actually programmed in C. • Because of the nature of C, Node can perform amazingly well when dealing with networking and OS system calls

  4. Asynchronous and evented • In the browser • Asynchronous Ajax request using XMLHttpRequest • I/O doesn’t block execution • Callback function • The code was not written like this • I/O blocks execution until finished $.post('/resource.json', function (data) { console.log(data); }); // script execution continues var data = $.post('/resource.json'); console.log(data);

  5. Concurrency: Event Loop • Instead of threads, Node uses an event loop with a stack • Alleviates overhead of context switching • Event loop as a language construct instead of as a library • It process each request as events • E.g., HTTP server doesn’t wait for the IO operation to complete while it can handle other request at the same time. • To avoid blocking, it makes use of the event driven nature of JavaScript by attaching callbacks to I/O requests

  6. Concurrency: Event Loop • An example of non-blocking I/O in the browser

  7. Concurrency: Event Loop • Thread vs. Event Loop

  8. Node.js/HTTP vs. Apache • Node.js/HTTP • It's fast • It can handle tons of concurrent requests • It's written in JavaScript (which means you can use the same code server side and client side)

  9. NGNIX vs. Apache • NGNIX • An HTTP server useing an event loop with asynchronous I/O

  10. DIRTy applications • DIRTy application • Data-intensive real-timeapplication • Node.js is suitable for DIRTy application • Node.js includes a core set of modules for many types of network and file I/O. • Building blocks for I/O-based applications • HTTP, HTTPS, filesystem (POSIX), UDP, and NET (TCP). • The core is intentionally small, low-level, and uncomplicated. • Third-party modules build upon these blocks to offer greater abstractions for common problems.

  11. Example 1. Simple Async App. • Node.js install • http://nodejs.org/ • REFL 101 • http://thinkonweb.com/?p=423 • Node.js app using filesystem (fs) module var fs = require('fs'); fs.readFile('./resource.json', function (er, data) { console.log(data); })

  12. Example 2. Hello World HTTP Server • An HTTP server simply responding to any request with “Hello World” • Same server to make the request event explicit • var http = require('http'); • http.createServer(function (req, res) { • res.writeHead(200, {'Content-Type': 'text/plain'}); • res.end('Hello World\n'); • }).listen(3000); • console.log('Server running at http://localhost:3000/'); • var http = require('http'); • var server = http.createServer(); • server.on('request', function (req, res) { • res.writeHead(200, {'Content-Type': 'text/plain'}); • res.end('Hello World\n'); • }) • server.listen(3000); • console.log('Server running at http://localhost:3000/');

  13. Example 3. Streaming data • Stream is data distributed over time • By bringing data in chunk by chunk, the developer handles the data as it comes in instead of waiting for it all to arrive before acting. var stream = fs.createReadStream('./resource.json') stream.on('data', function (chunk) { console.log(chunk) }) stream.on('end', function () { console.log('finished') })

  14. Example 4. HTTP Streaming • An HTTP server streaming an image to a client • Node.js provides these DIRTy-by-default approach across multiple platforms • var http = require('http'); • var fs = require('fs'); • http.createServer(function (req, res) { • res.writeHead(200, {'Content-Type': 'image/png'}); • fs.createReadStream('./image.png').pipe(res); • }).listen(3000); • console.log('Server running at http://localhost:3000/');