12_NODEJS_COMP3322_f2017.pdf - COMP 3322 Modern Technologies on World Wide Web 1st semester 2017-2018 Node.js(O2 Dr C Wu Department of Computer Science

12_NODEJS_COMP3322_f2017.pdf - COMP 3322 Modern...

This preview shows page 1 - 8 out of 37 pages.

Dr. C Wu Department of Computer Science The University of Hong Kong Node.js (O2) 1st semester 2017-2018 COMP 3322 Modern Technologies on World Wide Web
Image of page 1
Roadmap Technologies for creating dynamic, interactive web pages PHP [server side] JavaScript (AJAX, jQuery) [client side] HTML5 [client side] Node.js [server side and client side] AngularJS [client side]
Image of page 2
Image of page 3
Overview of Node.js (cont’d) Node.js is primarily used to build web applications, making it similar to PHP main difference PHP is a blocking language, where commands execute only after the previous command has completed Node.js is a non-blocking language, implements event-driven programming using JavaScript, where commands execute in parallel and use callbacks to signal completion Node.js can be used to build other network applications as well, e.g., TCP server and TCP client
Image of page 4
Node.js creates network applications using a collection of " modules " that handle various core functionalities e.g., modules handle file system I/O, networking (HTTP, TCP, UDP, DNS, or TLS/SSL), binary data (buffers), cryptography functions, data streams, etc. thousands of open-source libraries have been built for Node.js There are many frameworks built on Node.js used to accelerate the development of web applications Express.js (most polular Node.js web application framework) Restify.js (built specifically for building correct REST web services) Hapi.js (another rich framework for building applications and services) etc. Overview of Node.js (cont’d) Node.js = Runtime Environment + JavaScript Library
Image of page 5
An exmple Node.js application A simple Web server implemented by main.js : var http = require ( "http" ); http . createServer ( function ( request , response ) { // Send the HTTP header // HTTP Status: 200 : OK // Content Type: text/plain response . writeHead ( 200 , { 'Content-Type' : 'text/plain' }); // Send the response body as "Hello World" response . end ( 'Hello World\n' ); }). listen ( 8081 ); // Console will print the message console . log ( 'Server running at ' ); on console: $ node main . js execute main.js to start the server Web browser display when accessing return the built-in HTTP module a callback function, called after server created Node.js makes heavy use of callbacks
Image of page 6
Express.js Express.js is the most popular Node.js
Image of page 7

Want to read all 37 pages?

Image of page 8

Want to read all 37 pages?

You've reached the end of your free preview.

Want to read all 37 pages?

  • Fall '13
  • Dr. C. Wu
  • Ajax

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture