Share
Embed
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
Transcript
34 slides
-
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 -
What is the session format? Talks (Short/Long) Lightning Talks (5
mins) Anything else you can think of -
What is the grand vision? To build a community of
folks who are aware and excited about technology -
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 -
Why this is beneficial? Fosters learning and growth Building community
Transparency and Understanding -
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 -
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 -
"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." -
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 -
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/'); -
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 -
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 -
Such an Epic Win Benefits No 'context' switching while developing
on the stack Front end developers can now do back-end development -
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 -
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 -
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 -
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 -
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! -
"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. -
Excellent Development Tooling Package Manager: NPM Automation: Grunt/Gulp Scaffolding Tool:
Yeoman https://www.npmjs.org/ http://gruntjs.com/ http://yeoman.io/ -
Node Package Manager npm ships with node default No transitive
dependencies hell! https://www.npmjs.org/ -
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/ -
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 -
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/ -
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/ -
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/ -
References & Places to Start http://www.toptal.com/nodejs/why-the-hell-would-i-use- node-js http://rickgaribay.net/archive/2012/01/28/node-is-not- single-threaded.aspx http://www.nodeschool.io/
http://stackoverflow.com/questions/2353818/how-do-i- get-started-with-node-js