17
A Seminar Report on: “NODE JS” Prepared by : Saloni Agrawal Roll. No. : U12CO029 Class : B.Tech –IV (Computer Engineering) 7 th Semester Year : 201516 Guided by : Mr. Vivek Champaneria Department of Computer Engineering Sardar Vallabhbhai National Institute of Technology, Surat 395007 (Gujarat), India

Salskdjasdaloni.doc

  • Upload
    z

  • View
    215

  • Download
    0

Embed Size (px)

DESCRIPTION

alskgjaslkg

Citation preview

Page 1: Salskdjasdaloni.doc

A Seminar Report on:

“NODE JS”

Prepared by : Saloni Agrawal

Roll. No. : U12CO029

Class : B.Tech –IV (Computer Engineering) 7th Semester

Year : 2015­16

Guided by : Mr. Vivek Champaneria

Department of Computer Engineering

Sardar Vallabhbhai National Institute of Technology,

Surat ­395007 (Gujarat), India

Page 2: Salskdjasdaloni.doc

Sardar Vallabhbhai National Institute of Technology,

Surat ­395007 (Gujarat), India

CERTIFICATE

This is to certify that the seminar report entitled Node JS is

prepared and presented byMs. Saloni Agrawalbearing Roll No. :

U12CO029, 4th Year of B. Tech (Computer Engineering) and

her work is satisfactory.

GUIDE JURY(s) HOD

(Mr. Vivek Champaneria) COED

Page 3: Salskdjasdaloni.doc

Index

1 List Of Figures iv 2 Nomenclature v 3 Abstract vi 4 Chapter I : Introduction 1

iii

Page 4: Salskdjasdaloni.doc

List Of Figures

iv

Page 5: Salskdjasdaloni.doc

Nomenclature

iv

Page 6: Salskdjasdaloni.doc

Abstract

Node.js is an open­source, cross­platform runtime environment for developing server­side web applications. Node.js was invented in 2009 by Ryan Dahl and other developers working at Joyent. Node.js applications are written in JavaScript and can be run within the Node.js runtime on OS X, Microsoft Windows, Linux, FreeBSD, IBM System z and IBM i. Its work is hosted and supported by the Node.js Foundation, a collaborative project at Linux Foundation.Node.js provides an event­driven architecture and a non­blocking I/O API. It uses Google V8 JavaScript engine to execute code, and a large percentage of the basic modules are written in JavaScript. With this report we shall understand the importance of this new, event driven platform and the key features which makes Node.js promising. If we go to a big technical conference, we’ll almost certainly find a few talks on Node.js

In general terms, we might hear “Node” (as it is most commonly referred to), is a

server­side solution for JavaScript, and in particular, for receiving and responding to HTTP requests. Is this really JavaScript? In fact, why in the world would anyone want to run JavaScript outside of a browser, let alone the server? These are some of the questions which shall be answered in this report.

Page 7: Salskdjasdaloni.doc

Chapter I : Introduction

Node.js allows the creation of web servers and networking tools using JavaScript and a collection of "modules" that handle various core functionality. Modules handle file system I/O, networking, binary data (buffers), cryptography functions, and other core functions. Node's modules use an API designed to reduce the complexity of writing server applications.

Frameworks can be used to accelerate the development of applications, and common frameworks are Express.js, Socket.IO and Connect. Node.js applications can run on Microsoft Windows, Unix and Mac OS X servers. Node.js applications can alternatively be written with CoffeeScript (an alternative form of JavaScript), Dart or Microsoft TypeScript or any language that can compile to JavaScript.

Node.js is a non­blocking language where commands execute in parallel, and use callbacks to signal completion. Node.js implements event­driven programming for web applications in JavaScript. Developers can create highly scalable servers without using threading, by using a simplified model of event­driven programming that uses callbacks to signal the completion of a task. Concurrency is difficult in many server­side programming languages, and often leads to poor performance. Node.js is designed to use the scripting language JavaScript for Unix network programming.

Node is similar in design to and influenced by systems like Ruby's Event Machine or Python's Twisted. Node takes the event model a bit further, it presents the event loop as a language construct instead of as a library. In other systems there is always a blocking call to start the event­loop. Node simply enters the event loop after executing the input script. Node exits the event loop when there are no more callbacks to perform. This behavior is like browser JavaScript, the event loop is hidden from the user.

Figure 1 : Conventional Request Handling By Web Servers

The figure 1 shows the conventional request handling methods by various servers. This is

Page 8: Salskdjasdaloni.doc

not concurrent and results in not a largely scalable web application. To improve on this aspect, in figure 2, we see the approach taken by Node.Js

Figure 2 : Request Handling In Node.JS

To understand the power and the term scalability better, we shall see the features of Node in the following section.

1.1 Features of Node.JS

When discussing Node.js, one thing that definitely should not be omitted is built­in support for package management using the NPM tool that comes by default with every Node.js installation. The idea of NPM modules is quite similar to that of Ruby Gems: a set of publicly available, reusable components, available through easy installation via an online repository, with version and dependency management. A full list of packaged modules can be found on the NPM website https://npmjs.org/ , or accessed using the NPM CLI tool that automatically gets installed with Node.js.

Node has the following major features which makes it more trendy framework in today’s perspective:

1. JSON JSON is the most popular Data Exchange format presently. JSON and JavaScript

have reinforced each other's importance. JSON has enabled JavaScript developers to quickly construct APIs and foster interoperability at scale ­­ a key objective for Node.js coders.

2. JavaScript is everywhere It's the only choice for developing applications in the browser, with a new

framework introduced every week to woo developers. And with Node.js, JavaScript has

Page 9: Salskdjasdaloni.doc

spilled over to the server. Competing implementation teams have driven JavaScript interpreters forward, so that Google's V8 engine is respectably fast ­­ fast enough to reside at the core of Node.js.

3. Opensourced and Sharing is encouraged Sharing code under the MIT open source license is highly recommended in the

community, which also makes cross­pollination of code relatively worry­free from an intellectual property perspective. Finally, the community is highly engaged in binding interesting C libraries like computer vision (OpenCV) and the Tesseract open source optical character library.

4. NPM has strong support Node.js applications and Node.js Core itself are broken down into small modules

that are composed and shared. There are around 50 thousand packages which are regularly updated with a very supportive community.

5. Instrumentation Node is well built for production level usage. There are a lot of deployment tools

which also take care of the performance. Node is constantly updated and the next version is expected to be more robust.

In the following section we shall see some of the application areas of the Node.Js environment and see some application flow diagrams as well.

1.2 Applications of Node.JS

Node can be extended to a lot of server end applications. Some such applications can be a

chat server, an API on the top of a database, a series of queued request inputs, data streaming from the server or using the server as a proxy.

Figure 3 : Socket I/O on Node.JS

Page 10: Salskdjasdaloni.doc

Node can be used as a chat server by using socket I/O on various ports and the asynchronous callback based event driven system can be used as a stack of request handling system for the same. This broadcasting framework structure is seen in Figure 3. In Figure 4, we can see the database interaction of Node. It has various packages which are specialised for different databases but natively it supports a lot of connectivity. It creates a queue of requests and then interacts with the database from that queue one by one.

Figure 4 : Database Request Interaction in Node.JS

In the following chapter we shall see the comparison of Node with various web development frameworks. From this chapter, we have understood the basic properties and fundamentals associated with Node.

Page 11: Salskdjasdaloni.doc

CHAPTER II : COMPARISON WITH VARIOUS FRAMEWORKS

In this chapter, we aim to see practical world comparison of Node with other web development frameworks and try to derive some major advantages of using Node as primary environment. The tests are done by private organisations and we shall discuss only the final outcomes of the tests.

2.1 Node.js vs PHP

Figure 5 : Concurrency Benchmark Tests in PHP and NodeJS

One of the main advantages and differences node, is the fact that all executions are processed in a single thread. The process response is achieved at a higher rate of requested data, among many other advantages. JS executions are implicit as they require some sort of standby or lock ( which are handled with callbacks), and thus are faster. The figure 1 shows the scalable nature of single threaded calls on requests.

Node has following advantages against PHP in web development: 1. Fewer Dependencies

All requests to a PHP application must be routed via a web server which starts the PHP interpreter which runs the code. Node.js doesn’t need so many dependencies and, while you’ll almost certainly use a server framework such as Express, it’s lightweight and forms part of your application.

2. Light Weight Interpreter Node.js is smaller and nimbler than the PHP interpreter. It’s less encumbered

by legacy language support and Google has made a huge investment in V8 performance.

3. Applications are permanently ON PHP follows the typical client­server model. Every page request initiates our

application; we load configuration parameters, connect to a database, fetch information and render HTML. A Node.js app runs permanently and it need only initialize once. For example, we could create a single database connection object which is reused by everyone during every request.

Page 12: Salskdjasdaloni.doc

2.2 Node.js vs Ruby

The first point of comparison between Node and Ruby can be the number of packages in the respective package manager. And I’m glad to write that Node has taken a lead over Ruby. The following picture shows the growth in the count of packages supported by both.

Figure 6 : Package count comparison between Node and Ruby The full­stack Javascript approach is resultant into a lot less errors but it is difficult for a

beginner to learn. The learning curve is more simpler in the case of Ruby. Having said that, we can also say that the outcome of the steep learning curve is equally rewarding in terms of concurrent request handling and the smooth work­flow around Node. Node.js is a great set of tools that are hip, growing rapidly with a dedicated userbase, (debatably) high performance, easy(er) to pick up, and better than most other web building apps out there.

2.3 Node.js vs Java

There has not been much debate in the field of Node and Java. Node has always been a much faster, scalable and robust environment compared to Java. Following is a picture which is the result of tests conducted by the IBM research teams for handling API requests in both the frameworks. Node easily outscales Java.

Page 13: Salskdjasdaloni.doc

Figure 7 : IBM Comparison between Node and Java for API outputs

The only point of disadvantage for Node is the lack of multi threaded processing at the server end. This is easily contradicted by concurrent handling of requests by queues on single thread but the point of debate is always there. However, as the community grows at a very fast rate, Node will easily outscale the Java community on web development platform.

2.4 General Node Advantages

We can infer three major "wins" that Node.js has over most other development environments:

1. It's built to handle asynchronous I/O from the ground up. Other environments have asynchronous I/O features, but Node's the first environment where it's really pervasive. In most environments we’d find only limited pieces available in async. flavors, but in Node everything (or nearly everything) is async.­only. It's actually hard to write non­async. code in Node!

2. It's "just JavaScript." There is a homogeneous syntax flow in development. We dont have to switch between different languages. Every time we use some other Framework, context switch between that on the backend and JavaScript on the frontend, we waste large amounts of time making silly syntax errors. Staying in a single language feels faster.

3. It's new, so it has the benefit of being able to learn from previous languages' and environments' mistakes. Better, Node can correct those mistakes without the backwards­compatibility concerns. For example, the Node package installer, npm, is already quite a bit better than many of its equivalents. All in all, Node feels very polished and modern; it hasn't had time to accumulate the cruft other languages/environments have.

From this chapter, we have seen the industrial diversity in Node and the major advantages

of using it. In the following chapter we shall see some limitations of Node.Js and the places where it isn’t advised to use this framework.

Page 14: Salskdjasdaloni.doc

CHAPTER III : LIMITATIONS OF NODE.JS

We have seen the places where it is advisable to use Node as the primary development environment. However, we have to understand the limitations of the framework as well. In this chapter we shall see the sections where Node.JS shouldn’t be used, or we can get a better output from a different framework.

3.1 Server side Web Application with a Relational DB

Comparing Node.js with Express.js against Ruby on Rails, for example, there is a clean decision in favour of the latter when it comes to relational data access. Relational DB tools for Node.js are still in their early stages; they’re rather immature and not as pleasant to work with. On the other hand, Rails automatically provides data access setup right out of the box together with DB schema migrations support tools and other Gems. Rails and its peer frameworks have mature and proven Active Record or Data Mapper data access layer implementations.

3.2 Single Threaded Infrastructure

Node being single­threaded means that one does not need to care about the problems of synchronising between threads, or shared mutable state (given JS's semantics). However, it also means that unlike preemptive concurrency, the programmers themselves have to decide how to deal with concurrency, with the default being no concurrency at all! It's easy to write some part of the code that might take a long time to finish in some edge case, and then lock the whole system up. Not a good thing to happen. Green threads (like in Haskell), or lightweight processes with message passing for communication (like in Erlang) would be a better idea. JavaScript doesn't really have any good primitive for concurrency (although generators will allow cooperative concurrency, and can be used experimentally in Node today), and the core, along most libraries in the ecosystem, just straight up expect you to use continuation­passing style, which leads to non­compositional code, code bases that are difficult to reason about, and lots and lots of duplication.

3.3 Lack Of Maturity

Most of the core libraries have reached the status of stable, and you can trust them to usually do the right thing. But the ecosystem itself is still fairly immature. It's also difficult to assess the quality of a particular module (core or otherwise) because of the lack of features for ensuring the quality of code from JavaScript itself. The way npm is structured also makes it quite difficult to find trust­able packages, and the ease of publishing our own package, alongside the Unix­philosophy that runs through part of the community, making it harder to spot packages that are reliable and proven. Still in its early stages, Node has a fear of failure against the pre­existing frameworks.

Page 15: Salskdjasdaloni.doc

CHAPTER IV : CONCLUSION

We’ve discussed Node.js from theory to practice, beginning with its goals and ambitions, and ending with its sweet spots and pitfalls. When people run into problems with Node, it almost always boils down to the fact that blocking operations are the root of all evil—99% of Node misuses come as a direct consequence. Node.js was never created to solve the compute scaling problem. It was created to solve the I/O scaling problem, which it does really well. Why use Node.js? If your use case does not contain CPU intensive operations nor access any blocking resources, you can exploit the benefits of Node.js and enjoy fast and scalable network applications. One can understand some of the major advantages and disadvantages and industrial reachability of Node with this report, aiming to educate and spread more information about the same.

Page 16: Salskdjasdaloni.doc

REFERENCES

1. Why The Hell Would I Use Node.js? By Tomislav Capan 2. Node.js ­ Wikipedia Encyclopedia

a. https://en.wikipedia.org/wiki/Node.js 3. Nodejs.org Website 4. Quora Answers on Advantages Of Nodejs vs Python

Page 17: Salskdjasdaloni.doc

ACKNOWLEDGEMENT

I take this opportunity to express my deep sense of gratitude and indebtedness to our Project Guide ―Mr. Vivek Champaneria in Computer Engineering Department, S.V.N.I.T, Surat for his valuable guidance, useful comments and co­operation with kind and encouraging attitude at all stages of the research work for the successful completion of this report. I am also thankful to S.V.N.I.T, Surat and its staff for providing this opportunity which helped us in gaining sufficient knowledge and to make this Seminar Report successful.