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

Node.js Introduction

Node.js Introduction

A brief introduction to Node.js given at the Grand Rapids Web Development Group.

Brandon Keepers

March 26, 2012
Tweet

More Decks by Brandon Keepers

Other Decks in Programming

Transcript

  1. nodejs.org 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.
  2. $ node webserver.js var http = require('http'), server = http.createServer();

    server.on('request', function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }); server.listen(1337, "127.0.0.1"); console.log('Server running at http://127.0.0.1:1337/'); webserver.js
  3. // blocking var files = fs.readdirSync('/tmp') for(var i = 0;

    i < files.length; i++) { var file = files[i]; fs.unlinkSync('/tmp/' + file); console.log('successfully deleted ' + file); }
  4. // blocking var files = fs.readdirSync('/tmp') for(var i = 0;

    i < files.length; i++) { var file = files[i]; fs.unlinkSync('/tmp/' + file); console.log('successfully deleted ' + file); } // non-blocking fs.readdir('/tmp', function(err, files) { for(var i = 0; i < files.length; i++) { var file = files[i]; fs.unlink('/tmp/' + file, function (err) { if (err) throw err; console.log('successfully deleted ' + file); }); } });
  5. package.json $ npm install { "name": "myapp", "version": "0.0.1", "dependencies":

    { "socket.io": "0.8.7", "coffee-script": "1.2.0", "spine": "~1.0.5" } }