Node.js Hackathon

Preview:

Citation preview

7/31/2019 Node.js Hackathon

http://slidepdf.com/reader/full/nodejs-hackathon 1/19

7/31/2019 Node.js Hackathon

http://slidepdf.com/reader/full/nodejs-hackathon 2/19

Who are you?

•bit.ly/rcorsaro

• @doki_pen

• github.com/dokipen

•works @ embed.ly

7/31/2019 Node.js Hackathon

http://slidepdf.com/reader/full/nodejs-hackathon 3/19

Agenda

• Nodejs intro

•  API Recipe

• Demo

• Questions

7/31/2019 Node.js Hackathon

http://slidepdf.com/reader/full/nodejs-hackathon 4/19

 

Node Intro

7/31/2019 Node.js Hackathon

http://slidepdf.com/reader/full/nodejs-hackathon 5/19

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

7/31/2019 Node.js Hackathon

http://slidepdf.com/reader/full/nodejs-hackathon 6/19

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

7/31/2019 Node.js Hackathon

http://slidepdf.com/reader/full/nodejs-hackathon 7/19

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/');

7/31/2019 Node.js Hackathon

http://slidepdf.com/reader/full/nodejs-hackathon 8/19

Debugging

https://github.com/dannycoates/node-inspector 

7/31/2019 Node.js Hackathon

http://slidepdf.com/reader/full/nodejs-hackathon 9/19

Testing

• https://github.com/visionmedia/should.js

• https://github.com/visionmedia/mocha

• https://github.com/visionmedia/supertest

7/31/2019 Node.js Hackathon

http://slidepdf.com/reader/full/nodejs-hackathon 10/19

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" 

}

7/31/2019 Node.js Hackathon

http://slidepdf.com/reader/full/nodejs-hackathon 11/19

 

API Recipe

7/31/2019 Node.js Hackathon

http://slidepdf.com/reader/full/nodejs-hackathon 12/19

API Recipe (Yak Shaving)

• 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)

7/31/2019 Node.js Hackathon

http://slidepdf.com/reader/full/nodejs-hackathon 15/19

Authentication

If your API is public, you'll want to do thefollowing.

• 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)

7/31/2019 Node.js Hackathon

http://slidepdf.com/reader/full/nodejs-hackathon 16/19

Usage Tracking

 Analytics vs. Rate Limiting

Sync vs. Async

7/31/2019 Node.js Hackathon

http://slidepdf.com/reader/full/nodejs-hackathon 17/19

Access Control

• Support JSONP

• Support CORS

http://enable-cors.org/

Access-Control-Allow-Methods: GET, OPTIONS

Access-Control-Allow-Origin: *

7/31/2019 Node.js Hackathon

http://slidepdf.com/reader/full/nodejs-hackathon 18/19

 

Demo

7/31/2019 Node.js Hackathon

http://slidepdf.com/reader/full/nodejs-hackathon 19/19

 

Questions

Recommended