The Server-side JavaScript

Slides:



Advertisements
Similar presentations
Android Application Development A Tutorial Driven Course.
Advertisements

Tornado Web and MongoDB An Introduction to AsyncMongo MongoBoston John C. Zablocki Development Manager, HealthcareSource Organizer, Beantown.
PHP syntax basics. Personal Home Page This is a Hypertext processor It works on the server side It demands a Web-server to be installed.
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
Introduction to Web Based Application. Web-based application TCP/IP (HTTP) protocol Using WWW technology & software Distributed environment.
1 CS428 Web Engineering Lecture 18 Introduction (PHP - I)
Quick Tour of the Web Technologies: The BIG picture LECTURE A bird’s eye view of the different web technologies that we shall explore and study.
JavaScript Event Loop Not yo mama’s multithreaded approach. slidesha.re/ZPC2nD.
 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.
Presented by…. Group 2 1. Programming language 2Introduction.
ITM352 PHP and Dynamic Web Pages: Server Side Processing.
Written by Matthew Shelley for Professor Wei Shi.
Lecture 3 – Data Storage with XML+AJAX and MySQL+socket.io
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
Architecture Of ASP.NET. What is ASP?  Server-side scripting technology.  Files containing HTML and scripting code.  Access via HTTP requests.  Scripting.
Ole Erecius Tirsdag den 9. juni Programming is always at The EDGE !!!
JavaScript & jQuery the missing manual Chapter 11
ASP.NET INTRODUCTION INTO وزارة التربية و التعليم العالي كلية العلوم و التكنولوجيا قسم علوم الحاسوب و تكنولوجيا المعلومات اعداد الاستاذ: عبد الله محمد.
Open Web App. Purpose To explain Open Web Apps To explain Open Web Apps To demonstrate some opportunities for a small business with this technology To.
Introduction to Internet Programming (Web Based Application)
Node.js - What is Node.js? -
An Introduction to Front-end Web Development Tom Perkins.
CS 4720 Dynamic Web Applications CS 4720 – Web & Mobile Systems.
Chat Room App Logan Linn Network Application Design Fall 2010.
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.
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
CGS 3066: Web Programming and Design Spring 2016 Introduction to Server-Side Programming.
Best Web Technologies for
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.
Introduction to Node.js® Jitendra Kumar Patel Saturday, January 31, 2015.
Web Development. Agenda Web History Network Architecture Types of Server The languages of the web Protocols API 2.
Web-Technology Lecture 7.
Profound.js: The future of open source development on IBM i
CGS 3066: Web Programming and Design Spring 2017
JQuery Fundamentals Introduction Tutorial Videos
NodeJS and MEAN cs6320.
Web Technologies Computing Science Thompson Rivers University
Top 8 Best Programming Languages To Learn
Javascript and Dynamic Web Pages: Client Side Processing
Node.Js Server Side Javascript
ITM352 PHP and Dynamic Web Pages: Server Side Processing 1.
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
A lot of Software Development is about learning
Node.Js Server Side Javascript
2017, Fall Pusan National University Ki-Joune Li
Client/Server Computing and Web Technologies
NodeJS coding basics L. Grewe.
03 | Building a Backend with Socket.IO and Mongo
Application Development A Tutorial Driven Course
Nathan Totten Technical Evangelist Windows Azure
Web Programming Language
Secure Web Programming
INTRODUCTION TO By Stepan Vardanyan.
Week 01 Node.js Week 01
Lecture 12: The Fetch Api and AJAx
Lecture 14: JSON and Web SERVICES
Week 02 Node.js Week 02
Web Technologies Computing Science Thompson Rivers University
Introduction.
Twitter Bot with NodeJS
Client Server Architecture and Data Persistence Options
Web Application Development Using PHP
Presentation transcript:

The Server-side JavaScript Vikash Singh

What to expect ahead…. Introduction Some (Confusing) Theory 5 Examples A couple of weird diagrams 2 Pics showing unbelievable benchmarks Some stuff from Internet And Homer Simpson

Background V8 is an open source JavaScript engine developed by Google. Its written in C++ and is used in Google Chrome Browser. Node.js runs on V8. It was created by Ryan Dahl in 2009. Is still in Beta phase. Latest version is 0.6.11 Is Open Source. It runs well on Linux systems, can also run on Windows systems. If you have worked on EventMachine (Ruby) or Python’s Twisted or Perl’s AnyEvent framework then following presentation is going to be very easy.

Introduction: Basic In simple words Node.js is ‘server-side JavaScript’. In not-so-simple words Node.js is a high-performance network applications framework, well optimized for high concurrent environments. It’s a command line tool. In ‘Node.js’ , ‘.js’ doesn’t mean that its solely written JavaScript. It is 40% JS and 60% C++. From the official site: ‘Node's goal is to provide an easy way to build scalable network programs’ - (from nodejs.org!)

Introduction: Advanced (& Confusing) Node.js uses an event-driven, non-blocking I/O model, which makes it lightweight. (from nodejs.org!) It makes use of event-loops via JavaScript’s callback functionality to implement the non-blocking I/O. Programs for Node.js are written in JavaScript but not in the same JavaScript we are use to. There is no DOM implementation provided by Node.js, i.e. you can not do this: var element = document.getElementById(“elementId”); Everything inside Node.js runs in a single-thread.

Example-1: Getting Started & Hello World Install/build Node.js. (Yes! Windows installer is available!) Open your favorite editor and start typing JavaScript. When you are done, open cmd/terminal and type this: ‘node YOUR_FILE.js’ Here is a simple example, which prints ‘hello world’ var sys = require(“sys”); setTimeout(function(){ sys.puts(“world”);},3000); sys.puts(“hello”); //it prints ‘hello’ first and waits for 3 seconds and then prints ‘world’

Some Theory: Event-loops Event-loops are the core of event-driven programming, almost all the UI programs use event-loops to track the user event, for example: Clicks, Ajax Requests etc. Client Clients send HTTP requests to Node.js server Event loop (main thread) An Event-loop is woken up by OS, passes request and response objects to the thread-pool Event loop returns result to client Long-running jobs run on worker threads Response is sent back to main thread via callback C++ Threadpool (worker threads)

Some Theory: Non-Blocking I/O Traditional I/O var result = db.query(“select x from table_Y”); doSomethingWith(result); //wait for result! doSomethingWithOutResult(); //execution is blocked! Non-traditional, Non-blocking I/O db.query(“select x from table_Y”,function (result){ }); doSomethingWithOutResult(); //executes without any delay!

What can you do with Node.js ? You can create an HTTP server and print ‘hello world’ on the browser in just 4 lines of JavaScript. (Example included) You can create a TCP server similar to HTTP server, in just 4 lines of JavaScript. (Example included) You can create a DNS server. You can create a Static File Server. You can create a Web Chat Application like GTalk in the browser. Node.js can also be used for creating online games, collaboration tools or anything which sends updates to the user in real-time.

Example -2 &3 (HTTP Server & TCP Server) Following code creates an HTTP Server and prints ‘Hello World’ on the browser: var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(5000, "127.0.0.1"); Here is an example of a simple TCP server which listens on port 6000 and echoes whatever you send it: var net = require('net'); net.createServer(function (socket) { socket.write("Echo server\r\n"); socket.pipe(socket); }).listen(6000, "127.0.0.1");

Node.js Ecosystem Node.js heavily relies on modules, in previous examples require keyword loaded the http & net modules. Creating a module is easy, just put your JavaScript code in a separate js file and include it in your code by using keyword require, like: var modulex = require(‘./modulex’); Libraries in Node.js are called packages and they can be installed by typing npm install “package_name”; //package should be available in npm registry @ nmpjs.org NPM (Node Package Manager) comes bundled with Node.js installation.

Example-4: Lets connect to a DB (MongoDB) Install mongojs using npm, a mongoDB driver for Node.js npm install mongojs Code to retrieve all the documents from a collection: var db = require("mongojs") .connect("localhost:27017/test", ['test']); db.test.find({}, function(err, posts) { if( err || !posts) console.log("No posts found"); else posts.forEach( function(post) { console.log(post); });

When to use Node.js? Node.js is good for creating streaming based real-time services, web chat applications, static file servers etc. If you need high level concurrency and not worried about CPU-cycles. If you are great at writing JavaScript code because then you can use the same language at both the places: server-side and client-side. More can be found at: http://stackoverflow.com/questions/5062614/how-to- decide-when-to-use-nodejs

Example-5: Twitter Streaming Install nTwitter module using npm: Npm install ntwitter Code: var twitter = require('ntwitter'); var twit = new twitter({ consumer_key: ‘c_key’, consumer_secret: ‘c_secret’, access_token_key: ‘token_key’, access_token_secret: ‘token_secret’}); twit.stream('statuses/sample', function(stream) { stream.on('data', function (data) { console.log(data); }); });

Some Node.js benchmarks Taken from: http://code.google.com/p/node-js-vs-apache-php-benchmark/wiki/Tests A benchmark between Apache+PHP and node.js, shows the response time for 1000 concurrent connections making 10,000 requests each, for 5 tests. Taken from: http://nodejs.org/jsconf2010.pdf The benchmark shows the response time in milli-secs for 4 evented servers.

When to not use Node.js When you are doing heavy and CPU intensive calculations on server side, because event-loops are CPU hungry. Node.js API is still in beta, it keeps on changing a lot from one revision to another and there is a very little backward compatibility. Most of the packages are also unstable. Therefore is not yet production ready. Node.js is a no match for enterprise level application frameworks like Spring(java), Django(python), Symfony(php) etc. Applications written on such platforms are meant to be highly user interactive and involve complex business logic. Read further on disadvantages of Node.js on Quora: http://www.quora.com/What-are-the-disadvantages-of-using- Node-js

Appendix-1: Who is using Node.js in production? Yahoo! : iPad App Livestand uses Yahoo! Manhattan framework which is based on Node.js. LinkedIn : LinkedIn uses a combination of Node.js and MongoDB for its mobile platform. iOS and Android apps are based on it. eBay : Uses Node.js along with ql.io to help application developers in improving eBay’s end user experience. Dow Jones : The WSJ Social front-end is written completely in Node.js, using Express.js, and many other modules. Complete list can be found at: https://github.com/joyent/node/wiki/Projects,- Applications,-and-Companies-Using-Node

Appendix-2: Resource to get started Watch this video at Youtube: http://www.youtube.com/watch?v=jo_B4LTHi3I Read the free O’reilly Book ‘Up and Running with Node.js’ @ http://ofps.oreilly.com/titles/9781449398583/ Visit www.nodejs.org for Info/News about Node.js Watch Node.js tutorials @ http://nodetuts.com/ For Info on MongoDB: http://www.mongodb.org/display/DOCS/Home For anything else Google!

Appendix-3: Some Good Modules Express – to make things simpler e.g. syntax, DB connections. Jade – HTML template system Socket.IO – to create real-time apps Nodemon – to monitor Node.js and push change automatically CoffeeScript – for easier JavaScript development Find out more about some widely used Node.js modules at: http://blog.nodejitsu.com/top-node-module-creators