Node.Js 1. 2 Contents About Node.Js Web requirement latest trends Introduction Simple web server creation in Node.Js Dynamic Web pages Dynamic web page.

Slides:



Advertisements
Similar presentations
PHP I.
Advertisements

JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
Java Script Session1 INTRODUCTION.
Internet of Things with Intel Edison Web controller
HTTP Request/Response Process 1.Enter URL ( in your browser’s address bar. 2.Your browser uses DNS to look up IP address of server.com.
N ODE.J S S ERVER S IDE J AVASCRIPT Diana Roiswati ( ) Ahmad Syafii ( ) Asri Taraqiadiyu ( )
© 2014 IBM Corporation Empowering the IBM ecosystem Introduction to Developing applications using node.js on Bluemix IBM Ecosystem Development Instructors.
Server-Side vs. Client-Side Scripting Languages
Multiple Tiers in Action
1 CS6320 – Why Servlets? L. Grewe 2 What is a Servlet? Servlets are Java programs that can be run dynamically from a Web Server Servlets are Java programs.
Computer Science 101 Web Access to Databases Overview of Web Access to Databases.
INTRO TO MAKING A WEBSITE Mark Zhang.  HTML  CSS  Javascript  PHP  MySQL  …That’s a lot of stuff!
1 CS428 Web Engineering Lecture 18 Introduction (PHP - I)
Web Page A page displayed by the browser. Website Collection of multiple web pages Web Browser: A software that displays web pages on client computer.
PHP and MySQL Week#1  Course Plan.  Introduction to Dynamic Web Content.  Setting Up Development Server Eng. Mohamed Ahmed Black 1.
 A JavaScript runtime environment running Google Chrome’s V8 engine ◦ a.k.a. a server-side solution for JS ◦ Compiles JS, making it really fast  Runs.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
Web server and web browser It’s a take and give policy in between client and server through HTTP(Hyper Text Transport Protocol) Server takes a request.
Intro to PHP Introduction to server-side scripts (It’s all good :D) © TAFE NSW
Written by Matthew Shelley for Professor Wei Shi.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
Architecture Of ASP.NET. What is ASP?  Server-side scripting technology.  Files containing HTML and scripting code.  Access via HTTP requests.  Scripting.
Programming Network Servers Topic 6, Chapters 21, 22 Network Programming Kansas State University at Salina.
PHP. Why should we learn web programming? No need write socket programming. - You can forget TCP/IP & OSI layers. - Web server handles socket tasks for.
Server-side Scripting Powering the webs favourite services.
Basics of Web Databases With the advent of Web database technology, Web pages are no longer static, but dynamic with connection to a back-end database.
Node.js - What is Node.js? -
Orbited Scaling Bi-directional web applications A presentation by Michael Carter
Web Pages with Features. Features on Web Pages Interactive Pages –Shows current date, get server’s IP, interactive quizzes Processing Forms –Serach a.
1 Welcome to CSC 301 Web Programming Charles Frank.
1 MSCS 237 Overview of web technologies (A specific type of distributed systems)
Web Pages with Features. Features on Web Pages Interactive Pages –Shows current date, get server’s IP, interactive quizzes Processing Forms –Serach a.
ASP (Active Server Pages) by Bülent & Resul. Presentation Outline Introduction What is an ASP file? How does ASP work? What can ASP do? Differences Between.
Zz SOCKET.IO going real time with Arnout Kazemier
Client-side & Server-side Scripting ©Richard L. Goldman August 5, 2003 Requires PowerPoint 2002 or later for full functionality.
Chat Room App Logan Linn Network Application Design Fall 2010.
Page 1 Node.js - What? EMEA PUG Challenge, November 2015, Copenhagen 6-Nov-15 Node.js - What?
ASP. ASP is a powerful tool for making dynamic and interactive Web pages An ASP file can contain text, HTML tags and scripts. Scripts in an ASP file are.
 Web pages originally static  Page is delivered exactly as stored on server  Same information displayed for all users, from all contexts  Dynamic.
1) PHP – Personal Home Page Scripting Language 2) JavaScript.
Javascript Overview. What is Javascript? May be one of the most popular programming languages ever Runs in the browser, not on the server All modern browsers.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 2: Introduction to IS2803 Rob Gleasure
Web Page Designing With Dreamweaver MX\Session 1\1 of 9 Session 1 Introduction to PHP Hypertext Preprocessor - PHP.
IN THIS LESSON WE WILL REVIEW THE STRUCTURE OF THE INTERNET AND HOW BROWSERS ASSEMBLE WEBSITES BASED ON INSTRUCTIONS THEY RECEIVE FROM SERVERS. Internet.
Learn Nodejs by Building 10 projects. What is Nodejs  An Open source, Cross platform, Event Based and Non-blocking framework used to develop server side.
JavaScript Invented 1995 Steve, Tony & Sharon. A Scripting Language (A scripting language is a lightweight programming language that supports the writing.
Introduction to Node.js® Jitendra Kumar Patel Saturday, January 31, 2015.
Presented By Sushil K. Chaturvedi Assistant Professor SRCEM,Banmore 1.
1 Chapter 1 INTRODUCTION TO WEB. 2 Objectives In this chapter, you will: Become familiar with the architecture of the World Wide Web Learn about communication.
NodeJS and MEAN cs6320.
Node.Js Server Side Javascript
The Server-side JavaScript
CSE 775 – Distributed Objects Submitted by: Arpit Kothari
NodeJS and MEAN Prof. L. Grewe.
3 Things Everyone Knows About Node JS That You Don't
AJAX.
PHP / MySQL Introduction
Node.js talking to PROGRESS
Node.Js Server Side Javascript
Database Driven Websites
2017, Fall Pusan National University Ki-Joune Li
Parallel Programming in Contemporary Programming Languages (Part 2)
Secure Web Programming
INTRODUCTION TO By Stepan Vardanyan.
Lecture 10: The Web Server Wednesday February 14, /10/2019
Chengyu Sun California State University, Los Angeles
Chengyu Sun California State University, Los Angeles
Web Application Development Using PHP
Presentation transcript:

Node.Js 1

2 Contents About Node.Js Web requirement latest trends Introduction Simple web server creation in Node.Js Dynamic Web pages Dynamic web page creation Loading of dynamic web pages Asynchronous Programming in Node.Js Node.Js event loop Example of sequential programming Event loop handler based programming Things to remember while developing Node.Js Real time communication in Node.Js Example of Real Time communication-Chat Application.

3 Node.js was created by Ryan Dahl in 2009 Node.js is a software platform used to build scalable network (especially server-side) applications Node.js is a packaged compilation of Google's V8 open source JavaScript engine. About Node.Js

4 Real time communication Chat, gaming, constant social media updates, collaboration –each of these features requires real time communication between users, clients, and servers across the web. Server needs to supports large No. of Clients Large numbers of clients poll the server simultaneously, hence it becomes incredibly slow and inefficient. Web requirement latest trends

5 Node.js is an event-driven, server-side JavaScript environment.  Node runs JavaScript using the V8 engine developed by Google for using it in their Chrome web browser. Executes JavaScript at lightning speeds  V8 compiles JavaScript in native machine code instead of executing it as byte code  A wrapper is built around V8 to make it execute JavaScript without the browser. Introduction

6 Node.js is open source and a cross-platform,  Runs on Mac OSX, Windows, and Linux.  It is possible to run a web server without the use of external software such as Apache.  Allows developers to create a web server with more control. Contd…

7 Example : Simple web server creation in Node.js var http = require("http"); http.createServer(function(request, response) { response.writeHead(200, {"Content-Type": "text/plain"}); response.write("Hello World"); response.end(); } }).listen(8080);

8 Dynamic web pages We can create a dynamic web page in the node.js  like php, jsp, jinja (Python) Jade – template engine can create a dynamic web page in node.js

9 NP Compete if (foo) { bar(1 + 5)} NP Compete Welcome to Node.js Programming Jade is a simple templating language with a strong focus on performance and powerful features. Rendered HTML pageThis is the node.js example for dynamic webpage creation. doctype 5 html(lang="en") head title= NP Compete script(type='text/javascript'). if (foo) { bar(1 + 5) } body h1 NP Compete #container.col p Welcome to Node.js Programming p Jade is a simple templating language with a strong focus on performance and powerful features. Dynamic web pages creation

10 How dynamic web page gets loaded. var http = require("http"),fs = require('fs'); http.createServer(function(request, response) { fs.readFile(__dirname + '/index.html', function (err, data) { if (err) { res.writeHead(500); return res.end('Error loading index.html'); } res.writeHead(200); res.end(data); }); } }).listen(8080); Read file is used to read the HTML file ( index.html) and send it back to the client.

11 The execution model of Node.js is different from other web servers There is only one single process. It has Event Loop to achieve multiple task execution. In other web servers each request will create a separate process. OS requires separate effort i.e memory and time for each process creation. Asynchronous Programming in Nodejs

12 To scale large volumes of clients, all I/O intensive operations in Node.js are performed asynchronously. When a Node application needs to perform a blocking operation (I/O operations, heavy computation, etc.) it sends an asynchronous task to the event loop, along with a call-back function, and then continues to execute the rest of its program. The event loop keeps track of the asynchronous operation, and executes the given call-back when it is completed Contd…

13 Node.js Event Loop

14 Example of sequential programming var result = database.query("SELECT * FROM hugetable"); console.log("Hello World"); In this example the first line queries a database for number rows and the second line prints "Hello World" to the console. Let's assume that the database query is really slow, then it will take several seconds to display the message in the console. This is not an efficient programming since the JavaScript interpreter of Node.js has to first read the complete result set from the database, and then it can execute the console.log() function.

15 database.query("SELECT * FROM hugetable", function(rows) { var result = rows; }); console.log("Hello World"); Nodejs takes the query and sends it to the database. But instead of waiting for it to be finished, it immediately executes the console.log(), When the database server has completed the operation it sends the result of the query that executes the function passed to database.query() Event Loop handler based programming

16 Things to remember while developing Node.JS While writing the program in Nodejs we need to keep in mind that all the complex operations are not mapped to single event loop. It needs to be to be subdivided into smaller independent operations and given to the event loop to achieve the best performance. In the below code we have shown that complex I/O operation has been performed.

17 var http = require("http"); var sleep = require('sleep'); // sleep here refers to - complex I/O operation http.createServer(function(request, response) { //while(true) //{ response.writeHead(200,{"Content- Type": "text/plain"}); response.write("Hello World"); response.end(); sleep.sleep(20); // it waits for till the I/O operation. //} }).listen(8888); Contd…

18 Real time communication in Nodejs Normal scenario requires the client to send a request and the server sends the data to the client. In node js because of the socket programming ( which is a persistent connection in node js) it is possible to perform real time communication between the client and the server. We have shown an example of live communication i.e. group chat between multiple user. Here we can see that when one user send a chat message to the server, it broadcasts the chat message to all the other users immediately without any periodic request from the client.

19 var app = require('http').createServer(handler) io = require('/usr/local/lib/node_modules/socket.io').listen(app) fs = require('fs') var sockets = []; app.listen(8080); function handler (req, res) { fs.readFile(__dirname + '/index.html', function (err, data) { if (err) { res.writeHead(500); return res.end('Error loading index.html'); } res.writeHead(200); res.end(data); }); } io.sockets.on('connection', function (socket) { socket.emit('message', { msg: 'welcome to the chat' }); socket.on('send', function (data) { io.sockets.emit('message', data); }); Example - Chat Application Server side code

20 Jade var socket = io.connect(' socket.on('message', function (data) { // Socket on listens to the server and gets executed immd when it gets the data from the server. console.log(data); document.getElementById("masg"). innerHTML = document.getElementById("masg").innerHTML +" "+data.msg; }); function sendMsg() { if(document.getElementById("msgTxt").value == "") { alert("Please type Message!"); } else { var text = document.getElementById("msgTxt").value; socket.emit('send', { msg: text}); } }; Message Send Client side code Contd…

Thank You!!! 21