Node.js Introduction for Makers Academy

Node.js Introduction for Makers Academy

Presentation show to the guys at Makers Academy about Node.js

39bb8762f3a25ebc00ebd75bc4f363af?s=128

Simon Wood

May 16, 2013
Tweet

Transcript

  1. An Introduction

  2. Hi I'm Simon Wood @hpoom http://about.me/hpoom

  3. What is Node.js? Node.js is a platform built on Chrome's

    JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non- blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices. nodejs.org
  4. History & Details Node.js was created by Ryan Dahl starting

    in 2009 Node.js is a packaged compilation of Google's V8 JavaScript engine and a core library, which is itself primarily written in JavaScript Current stable version is 0.10.6
  5. Why Javascript server side? Can use the same language you're

    using for client side app. One language deployed everywhere Lets us share code between the browser and the backend It is event-based so it's like Ajax only server side It has low resource overheads It's fast. Really fast!
  6. How to install it Using homebrew: brew install node Using

    macports: port install nodejs or install it from a compiled package
  7. First Node.js test test.js console.log( 'Hello World!' ); terminal /node-demos$

    node test.js Hello World! /node-demos$
  8. HTTP Hello World hello.js var http = require( 'http' );

    var server = http.createServer(); server.on( 'request', function( req, res ) { res.end( 'Hello World!' ); } ); server.listen( 1337, '127.0.0.1' ); console.log( 'Server running at http://127.0.0.1:1337' ); terminal /node-demos$ node hello.js Server running at http://127.0.0.1:1337
  9. HTTP Hello World

  10. Event driven jQuery - Client Side $( 'button' ).on( 'click',

    function( event ) { document.write( 'Event driven' ); } ); Node.js - Server Side server.on( 'request', function( req, res ) { res.write( 'Event driven' ); } );
  11. Non-blocking I/O Blocking I/O var post = db.query( 'select *

    from posts where id = 1' ); doSomethingWithPost( post ); doSomethingElse(); Non-blocking I/O callback = function( post ) { doSomethingWithPost( post ) } db.query(' select * from posts where id = 1', callback ); doSomethingElse();
  12. What's supported HTTP TCP Sockets File I/O Many DB connectors

    MySQL, Redis, MongoDB, and more...
  13. Packages & Extensions Packages written in Javascript Either small packages

    of tools code, frameworks, or libraries for talking to DB's etc Packages best managed with NPM Extensions written in C++ Used to extend the core functions available to Node.js Commonly used to write libraries for DB's etc
  14. What Node.js is good for? Long polling Keeping lots of

    concurrent connections open Having same code server and client side Networking operations Real time applications Great for chat applications, polling applications like gmail, games servers, API's, API Gateways, proxy servers
  15. When not to use Node.js Still use traditional languages like

    PHP, Python, Ruby for tradition web solutions You would not rewrite wordpress in Node.js It could do it, but it is not the best choice
  16. Who is using Node.js LinkedIn Ebay Microsoft Uber Yahoo Holiday

    Extras nodejs.org/industry
  17. Questions?