Upgrade to Pro — share decks privately, control downloads, hide ads and more …

An Introduction to Node.JS - Server Side Javascript

An Introduction to Node.JS - Server Side Javascript

DBS ITT Lunch and Learn Tech Sharing April 2014

Speakers

1. An Introduction to Node.JS - Server Side Javascript - Steve Teo

Steve Teo

April 10, 2014
Tweet

More Decks by Steve Teo

Other Decks in Technology

Transcript

  1. What is this all about? Once a month session @

    Thursday lunchtime Focus on the learning and sharing of technology Open to all folks who have a kin interest
  2. What is the grand vision? To build a community of

    folks who are aware and excited about technology
  3. How did this come about? Lack of a platform for

    learning/sharing of technology My experience with tech meetups, conferences, etc. Some encouragement from the folks around me
  4. What are the topics? Anything to do with technology Cool

    hacks Something you have been up to Something your team has been up to Not limited to those stated above
  5. How can you contribute? Be a speaker Be a co-organiser

    Be a sponsor (lunch!) Be an attendee Let others know about this Give useful feedback Anything else you can think of
  6. "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."
  7. Node.js Created by Ryan Dhal in 2009 Written in C

    & Javascript Official Website: Open source: Backed by Joyent It runs almost everywhere - Linux, Mac OS X, Windows, Solaris Similar concepts to libraries in other Frameworks Python's Twisted Ruby's Eventmachine http://www.nodejs.org https://github.com/joyent/node
  8. Our first node program var http = require('http'); http.createServer(function (req,

    res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(1337, '127.0.0.1'); console.log('Server running at http://127.0.0.1:1337/');
  9. Ok. So why was Javascript chosen? Lingua franca of the

    Internet Language Constructs Functions as first class citizens Support for Closures Dynamically typed Dynamic Objects and Prototypal inheritance Benefits Ideal for massive concurrency operations Rapid prototyping, rapid development
  10. Full Stack Javascript Baby! The Stack Client Side - Javascript

    Server Side - Javascript Native Data/Serialization Format - JSON Database - if you are using Mongodb, BSON data format
  11. Such an Epic Win Benefits No 'context' switching while developing

    on the stack Front end developers can now do back-end development
  12. Understanding Node- Internals Node is essentially consists of the following

    components Chrome's V8 Javascript Engine Libuv Abstraction Layer Libev (C Asynchronous Event Loop to tie in Node.js Thread Pool) libeio (Asynchronous I/O - POSIX) IOCP (Asynchronous I/O - Windows) C-Ares (DNS) Node.js API https://github.com/joyent/libuv
  13. V8 High Performance Javascript Engine Just in Time Compilation (JIT)

    to native machine code On-the-fly recompilation of "hot" functions ECMAScript Compliant Supports the following architectures: x64/86, ARMS, MIPS
  14. Difference with the Traditional Model Traditional Model Forking a thread

    for every request, or waits for available thread Event Loop Model Single thread, using callbacks Reference http://goo.gl/dXagZI
  15. Understanding the Node.js Event Loop Single Application Thread Design (just

    like your browser window) Runs on one CPU Event-driven model Non-blocking through callbacks
  16. Understanding the Node.js Event Loop Implications No concurrency handling mechanism

    to handle - Easy to think and design Everything is Asynchronous - Need some getting use to IPC between thread pool and application thread via queues and callbacks No context switching on application thread - FAST! Blocking on the application thread - BAD! Errors not caught will kill off the application thread - BAD!
  17. "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.
  18. Excellent Development Tooling Package Manager: NPM Automation: Grunt/Gulp Scaffolding Tool:

    Yeoman https://www.npmjs.org/ http://gruntjs.com/ http://yeoman.io/
  19. Node Package Manager npm ships with node default No transitive

    dependencies hell! https://www.npmjs.org/
  20. Popular Node Modules Express Connect Socket.IO Meteor Jade Passport and

    many many others! http://expressjs.com/ http://www.senchalabs.org/connect/ http://socket.io/ https://www.meteor.com/ http://jade-lang.com/ http://passportjs.org/
  21. When to use Node.js? Shell Scripts Rest-JSON APIs Socket applications

    Real-time web applications with Socket.io or Meteor.js Front-end to async accept requests and offload heavy processing via MQ Quick prototyping to build a MVP Rapidly evolving applications Presentations
  22. Who is using Node in Production? Linkedin (Back-end for mobile

    application) Paypal (Replacing most of their existing java stack) Other Banks Many, many others! http://nodejs.org/industry/
  23. Other 'node-able' use cases Node-webkit Nodebots Workshops And many others!

    https://github.com/rogerwang/node-webkit http://nodebots.io/ http://www.nodeschool.io/
  24. Some last words Javascript is the most important languages to

    pick up The ubiquity of Node.js means its popularity will accelerate Excellent, open and vibrant community around Node.js Begin to write some Node (Shell scripts, simple web servers) Join the #SingaporeJS Meetup! http://www.meetup.com/Singapore-JS/