Node - Js Hackathon
Node - Js Hackathon
Agenda
Node Intro
Why Node?
Async, fast enough for web programming Very active and talented community NPM makes code reuse a breeze Honestly, javascript isn't that bad
Installing Node
https://github.com/creationix/nvm
$ git clone git://github.com/creationx/nvm.git ~/nvm $ . ~/nvm/nvm.sh $ nvm install v0.8.6 $ nvm alias default 0.8.6
Hello World
var http = require('http'); http.createServer(function (request, response) { response.writeHead(200, {'Content-Type': 'text/plain'}); response.end('Hello World\n');}).listen(8124); console.log('Server running at http://127.0.0.1:8124/');
Debugging
https://github.com/dannycoates/node-inspector
Testing
NPM Everything
{
"name": "hackathon", "version": "0.0.1", "description": "My hackathon project", "main": "index.js", "scripts": { "test": "mocha" }, "dependencies": { "express": "3.0.0rc2", "mongodb": "0.0.1" }, "devDependencies": { "mocha": "*", "should": "*", "supertest": "*" }, "author": "Bob Corsaro", "license": "MIT" }
API Recipe
Documentation Performance tracking Authentication Usage tracking Access Control (rate-limits, privileges) The actual service (and tests)
There are companies that do a lot of this for you for $. (mashery, apigee, 3scale)
Documentation
Remember wsdls? Contracts matter. Discovery matters.
https://github.com/wordnik/swagger-node-express https://github.com/dokipen/express-endpoint
Performance Tracking
Authentication
If your API is public, you'll want to do the following.
Distribute keys (we have a django app for that) uuid4 is good Authenticate keys (we have a connect middleware for that) Support 2-legged OAuth. Version 1.0a is fine. Ability to block keys (we'll use it later)
Usage Tracking
Analytics vs. Rate Limiting Sync vs. Async
Access Control
Support JSONP Support CORS http://enable-cors.org/
Demo
Questions