18
NodeJS (Runtime Environment + JS Library) Platform

Node js (runtime environment + js library) platform

Embed Size (px)

Citation preview

Page 1: Node js (runtime environment + js library) platform

NodeJS (Runtime Environment + JS Library) Platform

P Veer

Page 2: Node js (runtime environment + js library) platform

Agenda

➢ What is Node JS?➢ What is NOT Node JS?➢ Features of Node JS➢ Advantages of Node JS➢ Limitations of Node JS➢ npm➢ npm Functionalities➢ ExpressJS➢ NodeJS RESTful API➢ Helloworld Example➢ References

Page 3: Node js (runtime environment + js library) platform

What is Node JS ?➢ Node JS is an Open Source JavaScript Platform used to develop fast and scalable

server-side and networking applications very easily.➢ Google’s V8 Engine is an Open Source JavaScript Engine for the Chrome Web

browser. V8 Engine is completely written in C++ Language.➢ Ryan Dahl is a big fan of “Google’s Gmail”. He was impressed by Gmail

performance and started created new Platform.➢ Ryan Dahl has developed a Server-Side Platform “Node JS” in 2009 on top of

Google’s V8 Engine. That means Node JS applications run on V8 Engine.➢ Unlike some UI Frameworks for example Angular JS, use to write Client-side

JavaScript, Node JS Platform is used to write Server-side JavaScript.➢ We can run Node JS applications on most of the OS Platforms like Windows, Linux,

Mac etc.

Page 4: Node js (runtime environment + js library) platform
Page 5: Node js (runtime environment + js library) platform

What is NOT Node JS?

➢ Node JS is a Platform. It is not a Framework or Web Framework. It is not a Language.

➢ It is a Platform which contains thousands of thousands of modules to develop wide variety of applications. We can install base Node JS Platform and update all your application required modules very easily.

➢ Node JS “Module” is also known as Package. Now onwards, when we refer Module means Node JS Package.

➢ Node JS is not for Multi-Threaded applications. It follows Single Thread with Event Loop architecture.

Page 6: Node js (runtime environment + js library) platform

Features of Node JS

➢ Modularity➢ Express JS➢ Non-blocking or Asynchronous IO➢ Event-Driven Asynchronous Platform➢ Databases integration➢ Template engines➢ Web Server➢ Better Socket API

Page 7: Node js (runtime environment + js library) platform

Advantages of Node JS➢ One Language and One Data Format➢ Open Source➢ Highly Scalable➢ Better Performance and Low Latency➢ Caching Modules➢ Less Problems with Concurrency➢ Easy to Extend and Lightweight➢ Faster Development and Easy to Maintain➢ REST API➢ Many Development Frameworks and Tools➢ Active Development Community

Page 8: Node js (runtime environment + js library) platform

Advantages of Node JS (Cont...)

➢ Unit Testing➢ Streaming Data➢ Creating Servers➢ It can handle thousands of concurrent connections with minimal overhead

(CPU/Memory) on a single process➢ Easy Module Loading process

Page 9: Node js (runtime environment + js library) platform

Limitations of Node JS

➢ It does NOT support Multi-threading programming.➢ It does support for Computational Intensive Tasks. Node JS struggles in handling of

very high computational intensive tasks, because whenever it does something long running task, it will queue all remaining incoming requests, because it follows Single-Thread Architecture with Event Loop.

➢ Don’t use Node JS for Blocking/Synchronous and CPU-intensive tasks.

Page 10: Node js (runtime environment + js library) platform

npm (Nodejs Package Manager):

npm makes it easy for JavaScript developers to share and reuse code, and it makes it easy to update the code that you're sharing.

These bits of reusable code are called packages, or sometimes modules. A package is just a directory with one or more files in it, that also has a file called "package.json" with some metadata about this package.

A typical application, such as a website, will depend on dozens or hundreds of packages. These packages are often small. The general idea is that you create a small building block which solves one problem and solves it well. This makes it possible for you to compose larger, custom solutions out of these small, shared building blocks.

Page 11: Node js (runtime environment + js library) platform

npm (Node Package Manager) Functionalities

Node Package Manager (npm) provides following two main functionalities:

➢ Online repositories for node.js packages/modules which are searchable on search.nodejs.org

➢ Command line utility to install Node.js packages, do version management and dependency management of Node.js packages.

➢ NPM comes bundled with Node.js installables after v0.6.3 version. To verify the same, open console and type following command and see the result:

➢ $npm --version

Page 12: Node js (runtime environment + js library) platform

ExpressJS

Express is a minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications.

Following are the features of ExpressJS:

➢ Expressjs is a nodejs framework for parsing the payload, handling cookies.➢ Express.js has memory storage for sessions and can also be used with Redis➢ Can be used to load server static files➢ Expressjs provides routing to implement and handle Rest services.➢ provides middleware to routing which can be used for protecting api calls.➢ Uses default template engines (Jade, haml) for views rendering.➢ Start and Create server connections with nodeJS.

Page 13: Node js (runtime environment + js library) platform

NodeJS RESTful API

Nodejs can support the restful api development. Many web applications can build by the node modules.

Some of the following modules helps to RESTful API:

Http: Used to invoke all rest methods (GET, POST, PUT, DELETE, OPTIONS)Express: Web framework Require : Used to load the modules and callbacks

Page 14: Node js (runtime environment + js library) platform

Hello world example

➢ Step 1: First create a directory named myapp, change to it and run npm init. Then install express as a dependency, as per the installation guide. In the myapp directory, create a file named app.js and add the following code:

var express = require('express');var app = express();app.get('/', function (req, res) { res.send('Hello World!');});app.listen(3000, function () { console.log('Example app listening on port 3000!');});

➢ Step 2: Run the app with the following command: $ node app.js➢ Step 3: Load http://localhost:3000/ in a browser to see the output.

Page 15: Node js (runtime environment + js library) platform

Technologies used with NodeJS

Page 16: Node js (runtime environment + js library) platform

NodeJS Usage Chart

Page 18: Node js (runtime environment + js library) platform

Thank You