Introduction to Node.JS By Derek Anderson
I CAN HAS SERVER-SIDE !!?
What is Node.JS? Evented I/O for V8 JavaScript
What is Node.JS? Evented I/O for V8 JavaScript
What is Node.JS? Evented I/O for V8 JavaScript
Why? Node's goal is to provide an easy way to build scalable network programs. - nodejs.org
Traditional I/O var data = fs.readFile('large.mov'); // Wait until file.read finishes doSomethingWith(data); Waiting for disk operation to finish is slow!
Asynchronous I/O fs.readFile('large.mov', function(data){ doSomethingWith(data); }); // Do Something Else Right Away! doSomethingElse(); Read from the disk, and fire a callback when done. Meanwhile, Do Something Else! Inspiration: Felix Geisendörfer
THE GOOD • JavaScript on the Server
THE GOOD • JavaScript on the Server • Desktop / Web / CLI Applications
THE GOOD • JavaScript on the Server • Desktop / Web / CLI Applications • Non Blocking I/O: DB, Filesystems, etc
THE GOOD • JavaScript on the Server • Write CLI / GUI Applications • Non Blocking I/O: DB, Filesystems, etc • NPM : Node Package Manager
THE GOOD • JavaScript on the Server • Write CLI / GUI Applications • Non Blocking I/O: DB, Filesystems, etc • NPM : Node Package Manager • Active and friendly Community
Getting Started
Installation Compile from Source https://github.com/joyent/node/wiki/Installation Install NPM $ curl http://npmjs.org/install.sh | sh
Hello World /hello-world.js console.log('Hello World'); $ node hello-world.js Hello World
Core Modules • HTTP/HTTPS - Rock on!
Core Modules • HTTP/HTTPS - Rock on! • TCP - That’s nifty...
Core Modules • HTTP/HTTPS - Rock on! • TCP - That’s nifty... • DNS - Perform DNS operations
Core Modules • HTTP/HTTPS - Rock on! • TCP - That’s nifty... • DNS - Perform DNS operations • Filesystems - read/write/watch !!
Core Modules • HTTP/HTTPS - Rock on! • TCP - That’s nifty... • DNS - Perform DNS operations • Filesystems - read/write/watch !! • Crypto, SSL/TLS, Readline, etc...
Core Modules • HTTP/HTTPS - Rock on! • TCP - That’s nifty... • DNS - Perform DNS operations • Filesystems - read/write/watch !! • Crypto, SSL/TLS, Readline, etc... Over 3,400 Community Modules and counting ! http://search.npmjs.org/
Modules var fs = require('fs'), sys = require('sys'), http = require('http'), foo = require('./lib/foo'), bar = require('./lib/bar'); Import system wide modules such as fs, sys, http or local modules like /lib/foo.js
Roll Your Own Modules lib/say.js exports.say = function(something){ return something; } server.js var baz = require('./lib/say'); console.log(baz.say('Foo Bar!')); $ node server.js Foo Bar!
HTTP Server If you want to make an HTTP Server, you must first create the universe. - Carl Sagan
HTTP Server /hello-http.js var http = require('http') http.createServer(function(req, res){ res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World!'); }).listen(3000); console.log('Hello World'); $ node hello-http.js Server Running
HTTP Server
Resources & Tutorials
Resources & Tutorials List of Resources from Joyent https://github.com/joyent/node/wiki/Resources Node.js Beginners Guide http://nodeguide.com/beginner.html Read the API http://nodejs.org/docs/latest/api/
DEMO TIME
Questions ?http://github.com/mediaupstream email: derek@mediaupstream.com twitter: @derekanderson

Introduction to NodeJS with LOLCats

  • 1.
    Introduction to Node.JS By Derek Anderson
  • 2.
  • 3.
    What is Node.JS? EventedI/O for V8 JavaScript
  • 4.
    What is Node.JS? EventedI/O for V8 JavaScript
  • 5.
    What is Node.JS? EventedI/O for V8 JavaScript
  • 6.
    Why? Node's goal isto provide an easy way to build scalable network programs. - nodejs.org
  • 7.
    Traditional I/O var data= fs.readFile('large.mov'); // Wait until file.read finishes doSomethingWith(data); Waiting for disk operation to finish is slow!
  • 8.
    Asynchronous I/O fs.readFile('large.mov', function(data){ doSomethingWith(data); }); // Do Something Else Right Away! doSomethingElse(); Read from the disk, and fire a callback when done. Meanwhile, Do Something Else! Inspiration: Felix Geisendörfer
  • 9.
  • 10.
    THE GOOD • JavaScripton the Server • Desktop / Web / CLI Applications
  • 11.
    THE GOOD • JavaScripton the Server • Desktop / Web / CLI Applications • Non Blocking I/O: DB, Filesystems, etc
  • 12.
    THE GOOD • JavaScripton the Server • Write CLI / GUI Applications • Non Blocking I/O: DB, Filesystems, etc • NPM : Node Package Manager
  • 13.
    THE GOOD • JavaScripton the Server • Write CLI / GUI Applications • Non Blocking I/O: DB, Filesystems, etc • NPM : Node Package Manager • Active and friendly Community
  • 14.
  • 15.
    Installation Compile from Source https://github.com/joyent/node/wiki/Installation Install NPM $ curl http://npmjs.org/install.sh | sh
  • 16.
    Hello World /hello-world.js console.log('Hello World'); $ node hello-world.js Hello World
  • 17.
  • 18.
    Core Modules • HTTP/HTTPS- Rock on! • TCP - That’s nifty...
  • 19.
    Core Modules • HTTP/HTTPS- Rock on! • TCP - That’s nifty... • DNS - Perform DNS operations
  • 20.
    Core Modules • HTTP/HTTPS- Rock on! • TCP - That’s nifty... • DNS - Perform DNS operations • Filesystems - read/write/watch !!
  • 21.
    Core Modules • HTTP/HTTPS- Rock on! • TCP - That’s nifty... • DNS - Perform DNS operations • Filesystems - read/write/watch !! • Crypto, SSL/TLS, Readline, etc...
  • 22.
    Core Modules • HTTP/HTTPS - Rock on! • TCP - That’s nifty... • DNS - Perform DNS operations • Filesystems - read/write/watch !! • Crypto, SSL/TLS, Readline, etc... Over 3,400 Community Modules and counting ! http://search.npmjs.org/
  • 23.
    Modules var fs =require('fs'), sys = require('sys'), http = require('http'), foo = require('./lib/foo'), bar = require('./lib/bar'); Import system wide modules such as fs, sys, http or local modules like /lib/foo.js
  • 24.
    Roll Your OwnModules lib/say.js exports.say = function(something){ return something; } server.js var baz = require('./lib/say'); console.log(baz.say('Foo Bar!')); $ node server.js Foo Bar!
  • 25.
    HTTP Server If youwant to make an HTTP Server, you must first create the universe. - Carl Sagan
  • 26.
    HTTP Server /hello-http.js var http = require('http') http.createServer(function(req, res){ res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World!'); }).listen(3000); console.log('Hello World'); $ node hello-http.js Server Running
  • 27.
  • 28.
  • 29.
    Resources & Tutorials List of Resources from Joyent https://github.com/joyent/node/wiki/Resources Node.js Beginners Guide http://nodeguide.com/beginner.html Read the API http://nodejs.org/docs/latest/api/
  • 30.
  • 31.
    Questions ?http://github.com/mediaupstream email: derek@mediaupstream.com twitter: @derekanderson