Node js


Published on

  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Node js

  1. 1. Node JsEverything which you should know
  2. 2. Node.js for BeginnersEvent programming can be overwhelming for beginners, which can make Node.js difficult to get started with. But don’t let that discourage you, In this article, I will teach you some of the basics of Node.js and explain why it has become so popular.
  3. 3. IntroductionTo start using Node.js, you must first understand the differences between Node.js and traditional server-side scripting environments (eg: PHP, Python, Ruby, etc).
  4. 4. Asynchronous ProgrammingChances are good that you are familiar with asynchronous programming; it is, after all, the “A” in Ajax. Every function in Node.js is asynchronous. Therefore, everything that would normally block the thread is instead executed in the background. This is the most important thing to remember about Node.js. For example, if you are reading a file on the file system, you have to specify a callback function that is executed when the read operation has completed."Node.js uses a module architecture to simplify the creation of complex applications."
  5. 5. You are doing Everything!Node.js is only an environment – meaning that you have to do everything yourself. There is not a default HTTP server, or any server for that matter. This can be overwhelming for new users, but the payoff is a high performing web app. One script handles all communication with the clients. This considerably reduces the number of resources used by the application. For example, here is the code for a simple Node.js application:
  6. 6. ExamplesNode js PHPvar i, a, b, c, max; $a = null; $b = null; $c = null; $i = null; $max = 1000000000;max = 1000000000; $start = microtime(true);var d =; for ($i = 0; $i < $max; $i++) {for (i = 0; i < max; i++) { $a = 1234 + 5678 + $i; a = 1234 + 5678 + i; $b = 1234 * 5678 + $i; b = 1234 * 5678 + i; $c = 1234 / 2 + $i; c = 1234 / 2 + i; }} var_dump(microtime(true) - $start);console.log( - d);
  7. 7. The following table lists the response times, inmilliseconds, for these two simple applications: Number of iterations Node.js PHP 100 2.00 0.14 10’000 3.00 10.53 1’000’000 15.00 1119.24 10’000’000 143.00 10621.46 1’000’000’000 11118.00 1036272.19
  8. 8. I executed the two apps from the command line so that no server would delay the apps’ execution. I ran each test ten times and averaged the results. PHP is notably faster with a smaller amount of iterations, but that advantage quickly dissolves as the number of iterations increases. When all is said and done, PHP is 93% slower than Node.js!Node.js is fast, but you will need to learn a few things in order to use it properly.
  9. 9. ModulesNode.js uses a module architecture to simply the creation of complex applications. Each module contains a set of functions related to the “subject” of the module.Including a module is easy; simply call the require() function, like thisvar variable_name(module_name);
  10. 10. Global ScopeNode is a JavaScript environment running in Google’s V8 JavaScript engine.globalVariable = 1;globalFunction = function () { ... };
  11. 11. Installing New ModuleNode.js has a package manager, called Node Package Manager (NPM). It is automatically installed with Node.js, and you use NPM to install new modules. To install a module, open your terminal/command line, navigate to the desired folder, and execute the following command:npm install module_name
  12. 12. Let move ahead toJavascript Framework
  13. 13. er Frameworksower,Railway,Flatlron, etc Client Frameworks Backbone, Angular, Ember, etc Real-time Frameworks Derby, meteor, SocketStream
  14. 14. Thick Server -Websites
  15. 15. (eg, meetup) Mostfunctionality is still onserver, but client pages arehighly interactive and mayuse MVC for organization.
  16. 16. Cutting -Edge PresentThick-client: Web Apps, Mobile(eg, gmail) Most functionality onclient. The server is just RESTservice marshalling data
  17. 17. Little coding, largepay-off. Great forgames.
  18. 18. Node.js(Server) Frameworks
  19. 19. Why we use a Node Framework ?Why not vanilla Node, or •Module version compatibilities Express? •Boilerplate code •Authentication •Database setup •Grunt/Make tasks like minification, css/js compiling (Coffeescript, LESS, Stylus, etc) • •And much more
  20. 20. Express Railway>Express is a minimal and flexible >Railway is the Node.JS MVCnode.js web application framework, framework based on ExpressJS, fullyproviding a robust set of features for ExpressJS-compatible. It allows youbuilding single and multi-page, and to build web applications in a similarhybrid web applications. manner as in Ruby On Rails. Tower Flatlron No one agrees on frameworks. Its>Full Stack Web Framework for difficult to get consensus on how Node.js and the Browser. Built much or how little a framework on top of Nodes Connect and should do. Flatirons approach is to Express, modeled after Ruby on package simple to use yet full Rails. Built for the client and featured components and let server from the ground up. developers subtract or add what they want.
  21. 21. Derby MVC framework making it easy to write realtime, collaborativeapplications that run in both Node.js and browsers. MeteorMeteor is an open-source platform forbuilding top-quality web apps in afraction of the time, whether youre anexpert developer or just gettingstarted.
  22. 22. 18 Reasons Developers Are Using It for Cloud, Mobile Two Third Two-thirds of Americans access the Web through mobile devices, according to Engine Yard researchThirty-Four Percent And 34 percent of the worlds top 100 Websites are using HTML5.
  23. 23. The Rise of the real-time Web Engine Yard says the growth of mobile plus the popularity of HTML5 equals the rise of the real-time Web. And the real-time Web requires real-time technology, such as Node.js. Event-Driven:- Node.js is a development framework that uses an event-driven, non-blocking I/O.Built on Javascript :- Node.js is built on JavaScript to unify front-end and server-side architectures.High Performance :- Node.js is ideal for high-performance, highly scalable, distributed real-time Webapplications.
  24. 24. GitHub Status :- Node.js is the second-most-watchedrepository on the GitHub Web-based hosting service-second only to Bootstrap. Ruby on Rails :- Node.js is more watched than Ruby on Rails on GitHub. Bootstrap is first, Node.js second, jQuery third and Rails fourth.Node Package Manager :- Node Package Manager or NPM is a package manager and distribution system forNode.js. NPM has 12,000 modules and 3,800 active package authors.
  25. 25. LinkedIn LinkedIn is a prominent user of Node.js. On the server side, LinkedIns entire mobilesoftware stack is completely built in Node.js. The company went from running 15 serverswith 15 instances on each physical machine tojust four instances that can handle two times the traffic.
  26. 26. Walmart EbayWalmart re- eBay recently launched , a gateway for HTTP APIs, engineered its using Node.js as the mobile app to be runtime stack. eBay was powered by Node.js able to tune a regular and pushed all its quality Ubuntu workstation to handle more than JavaScript 120,000 active connections processing to the per Node.js process with server. each connection consuming about 2K of memory.
  27. 27. Key AppsNode.js is a good choice for building networked multiplayer games, interactive Websites and tools, Web analytics and online chat systems.
  28. 28. Why Developer Love Node.jsReason 1:Its JavaScript, the language of the Web.Reason 2:It supports code reuse at every level: browser, server side and database.Reason 3:It has a strong, passionate community.Reason 4:It offers performance and scalability.Reason 5:It leads to developer happiness.