drupal con nashville...what is node.js? node.js is a platform built on chrome's js runtime for...

26
DRUPAL CON NASHVILLE 2018 DRUPALCON NASHVILLE

Upload: others

Post on 20-Jun-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: DRUPAL CON NASHVILLE...What is Node.js? Node.js is a platform built on chrome's JS runtime for easily building fast, scalable network application. Node.js uses an event-driven, Non-Blocking

DRUPAL CON

NASHVILLE 2018

DRUPALCON NASHVILLE

Page 2: DRUPAL CON NASHVILLE...What is Node.js? Node.js is a platform built on chrome's JS runtime for easily building fast, scalable network application. Node.js uses an event-driven, Non-Blocking

DRUPAL CON

NASHVILLE 2018

Drupal 8: Realtime notification with node.js

Page 3: DRUPAL CON NASHVILLE...What is Node.js? Node.js is a platform built on chrome's JS runtime for easily building fast, scalable network application. Node.js uses an event-driven, Non-Blocking

Drupal 8: Realtime Notification with node.js

Sugandh KhannaSrijan, INDIA

Drupal CON NASHVILLEMarch 2018

Page 4: DRUPAL CON NASHVILLE...What is Node.js? Node.js is a platform built on chrome's JS runtime for easily building fast, scalable network application. Node.js uses an event-driven, Non-Blocking

AGENDA

1. Technologies used with Drupal 8 for the realtime app are as follows: a. Regular HTTP b. Ajax Polling c. Ajax Long Polling d. HTML5 SSE / EventSource e. HTML5 Websockets (with socket.io [a node.js library])2. What is node.js ?3. Node.js detailed in easiest way.4. Node.js VS Drupal 8.5. Integrate Drupal 8 with node.js for real time notification.

Page 5: DRUPAL CON NASHVILLE...What is Node.js? Node.js is a platform built on chrome's JS runtime for easily building fast, scalable network application. Node.js uses an event-driven, Non-Blocking

Regular Http a. Client sends a request to the server.b. The server check that request and make their calculation for their response on the basis of this request.c. The server finally sends the response to the client.

Page 6: DRUPAL CON NASHVILLE...What is Node.js? Node.js is a platform built on chrome's JS runtime for easily building fast, scalable network application. Node.js uses an event-driven, Non-Blocking

Ajax Pollinga. Client uses regular http.b. The client receives the response and executes the JavaScript on the page which requests a file from the server at regular intervals (e.g. 0.5 seconds).c. Each response calculated by and sends it back, just like normal HTTP traffic.

Page 7: DRUPAL CON NASHVILLE...What is Node.js? Node.js is a platform built on chrome's JS runtime for easily building fast, scalable network application. Node.js uses an event-driven, Non-Blocking

Ajax Long pollinga. Client uses resular http.b. The client receives the response and executes the JavaScript on the page which requests a file from the server.c. Server waits until there's new information available before responding.d. Now the server responds with the new information if available.e. The client receives the new information and immediately sends another request to the server, re-starting the process.

Page 8: DRUPAL CON NASHVILLE...What is Node.js? Node.js is a platform built on chrome's JS runtime for easily building fast, scalable network application. Node.js uses an event-driven, Non-Blocking

Ajax Long polling

Page 9: DRUPAL CON NASHVILLE...What is Node.js? Node.js is a platform built on chrome's JS runtime for easily building fast, scalable network application. Node.js uses an event-driven, Non-Blocking

HTML5 SSE / EventSource:

a. A client uses regular http.b. The client receives the response and executes the JavaScript on the page which requests a file from the server.c. The server sends an event to the client when there's new information available.

1. Real-time traffic from server to client, mostly that's what you'll need

2. You'll want to use a server that has an event loop

3. Not possible to connect with a server from another domain

Page 10: DRUPAL CON NASHVILLE...What is Node.js? Node.js is a platform built on chrome's JS runtime for easily building fast, scalable network application. Node.js uses an event-driven, Non-Blocking

HTML5 SSE / EventSource:

Page 11: DRUPAL CON NASHVILLE...What is Node.js? Node.js is a platform built on chrome's JS runtime for easily building fast, scalable network application. Node.js uses an event-driven, Non-Blocking

HTML5 Websocketsa. A client uses regular http.b. The client receives the response and executes the JavaScript on the page which requests a file from the server.c. The server and the client can now send each other messages when new data (on either side) is available. 1. Real-time traffic from the server to the client and from the client to the server 2. You'll want to use a server that has an event loop 3. With WebSockets it is possible to connect with a server from another domain. 4. It is also possible to use a third party hosted websocket server, for example Pusher or others. This way you'll only have to implement the client side, which is very easy!

Page 12: DRUPAL CON NASHVILLE...What is Node.js? Node.js is a platform built on chrome's JS runtime for easily building fast, scalable network application. Node.js uses an event-driven, Non-Blocking

HTML5 Websockets

Page 13: DRUPAL CON NASHVILLE...What is Node.js? Node.js is a platform built on chrome's JS runtime for easily building fast, scalable network application. Node.js uses an event-driven, Non-Blocking

What is Node.js?

Node.js is a platform built on chrome's JS runtime for easily building fast, scalable network application. Node.js uses an event-driven, Non-Blocking I/O model that makes light weight and efficient, perfect for data intensive real-time applications that run across distributed devices.

Page 14: DRUPAL CON NASHVILLE...What is Node.js? Node.js is a platform built on chrome's JS runtime for easily building fast, scalable network application. Node.js uses an event-driven, Non-Blocking

Node.js in some details:

a. Runs on Google V8 js engine.b. Uses an event driven, non-blocking I/O model.c. Can handle many thousands of connections on a single process. d. Well suited of real time communication.

Page 15: DRUPAL CON NASHVILLE...What is Node.js? Node.js is a platform built on chrome's JS runtime for easily building fast, scalable network application. Node.js uses an event-driven, Non-Blocking

Drupal Vs Node.JS

Page 16: DRUPAL CON NASHVILLE...What is Node.js? Node.js is a platform built on chrome's JS runtime for easily building fast, scalable network application. Node.js uses an event-driven, Non-Blocking

About Node.js Drupal 8 module

Made of two parts:

a. A set of Drupal 8 modules for adding real-time capabilities to a Drupal 8 site. b. A Node.js application built with the node modules socket.io, express and request which runs from the terminal.

Page 17: DRUPAL CON NASHVILLE...What is Node.js? Node.js is a platform built on chrome's JS runtime for easily building fast, scalable network application. Node.js uses an event-driven, Non-Blocking

About Node.js Drupal 8 module

NPM (Node Package Manager) a. Used to manage packages for node.js applications. b. Bundled with node.js. c. Packages are defined by package.json. d. Allows download and publishing of packages. e. NPM is package manager for JS.

Page 18: DRUPAL CON NASHVILLE...What is Node.js? Node.js is a platform built on chrome's JS runtime for easily building fast, scalable network application. Node.js uses an event-driven, Non-Blocking

About Node.js Drupal 8 modulesocket.io( node.js real-time framework server)How to useThe following example attaches socket.io to a plain Node.JS HTTP server listening on port 3000.

var server = require('http').createServer(); var io = require('socket.io')(server); io.on('connection', function(client){ client.on('event', function(data){}); client.on('disconnect', function(){}); }); server.listen(3000);

Page 19: DRUPAL CON NASHVILLE...What is Node.js? Node.js is a platform built on chrome's JS runtime for easily building fast, scalable network application. Node.js uses an event-driven, Non-Blocking

About Node.js Drupal 8 module

express( fast, unopinionated, minimalist web framework )How to use

var var express = require('express'); var app = express(); app.get('/', function (req, res) { res.send('Hello World'); }) app.listen(3000);

Page 20: DRUPAL CON NASHVILLE...What is Node.js? Node.js is a platform built on chrome's JS runtime for easily building fast, scalable network application. Node.js uses an event-driven, Non-Blocking

About Node.js Drupal 8 module

Page 21: DRUPAL CON NASHVILLE...What is Node.js? Node.js is a platform built on chrome's JS runtime for easily building fast, scalable network application. Node.js uses an event-driven, Non-Blocking

About Node.js Drupal 8 moduleDrupal 8 node.js module installation guide.

Update your local package index:

sudo apt-get update

Install Node.js:

sudo apt-get install nodejs

You will also want to install NPM, which lets you easily manage your different Node.js packages.

sudo apt-get install npm

Page 22: DRUPAL CON NASHVILLE...What is Node.js? Node.js is a platform built on chrome's JS runtime for easily building fast, scalable network application. Node.js uses an event-driven, Non-Blocking

About Node.js Drupal 8 module

Page 23: DRUPAL CON NASHVILLE...What is Node.js? Node.js is a platform built on chrome's JS runtime for easily building fast, scalable network application. Node.js uses an event-driven, Non-Blocking

Practical Demo with real-time data on local system

Page 24: DRUPAL CON NASHVILLE...What is Node.js? Node.js is a platform built on chrome's JS runtime for easily building fast, scalable network application. Node.js uses an event-driven, Non-Blocking

How external API communicate with Drupal 8

Page 25: DRUPAL CON NASHVILLE...What is Node.js? Node.js is a platform built on chrome's JS runtime for easily building fast, scalable network application. Node.js uses an event-driven, Non-Blocking

Any Questions ?

Page 26: DRUPAL CON NASHVILLE...What is Node.js? Node.js is a platform built on chrome's JS runtime for easily building fast, scalable network application. Node.js uses an event-driven, Non-Blocking

Thanks You!