Skip to content

Instantly share code, notes, and snippets.

View wesleytodd's full-sized avatar

Wes Todd wesleytodd

View GitHub Profile

Architecting Node Apps At A Startup

Startups move fast. Part of moving fast is being willing to make mistakes. At StreamMe we have moved fast, and made plenty of mistakes. We have also worked hard at finding solutions to move past those mistakes. Throughout this process we have found that the most important thing is not AVOIDING the mistakes, but eaisly setting up a system to rectify them when you have time.

One of the best things you can do to avoid the kind of mistake that takes months of work to dig yourself out of is setting a good foundation. The right kind of foundation will allow you to explore without encumbering your entire stack or application.

This talk I will go through some of the key mistakes we made at StreamMe, and what we have learned. Hopefully getting everyone to a place where they feel like they could start a new project on Node that will last for more than a month at a startup.

Architecting Node Apps At A Startup

Startups move fast. To keep up it is important to start with a good foundation. This talk will go through some of the mistakes we made at StreamMe, and what we have learned. Hopefully getting everyone to a place where they feel like they could start a new project on Node that will last for more than a month at a startup.

SOA

New features will happen, and development of them should not be hindered legacy code and practices. Writing your apps in a service oriented architecture can help with this. It means that when you start a new feature you can choose new tools and updated versions of tools and libraries.

Build your apps without dependencies

var http = require('v-http');
module.exports = function updateAccount (acct) {
return new Promise(function (resolve, reject) {
http({
method: 'PUT',
url: '/api-user/v1/me',
data: {
username: acct.username,
displayName: acct.displayName,
@wesleytodd
wesleytodd / dht.js
Last active October 25, 2015 20:23
An very basic example usage of k-bucket to route requests on a dht
var KBucket = require('k-bucket');
var crypto = require('crypto');
// Number of nodes
var NUM_NODES = 5;
var NUM_ITEMS = 100;
// Make the routing table
var router = new KBucket();
@wesleytodd
wesleytodd / gist:990f0292051c5210abbd
Last active August 29, 2015 14:20
Render example
var pubId = 'the starting value';
var render = function() {
// The right sidebar
var rightSidebar = module.exports = React.render((
<RightSidebar showCloseButton={false}>
<SidebarSection title="Register Complete" ref="register-complete">
<IframeComponent src={"/embed/" + pubId }/>
</SidebarSection>
</RightSidebar>
@wesleytodd
wesleytodd / callbacks.md
Last active August 29, 2015 14:06
Async Control Flow

Callbacks are great

function myDataGetterThingy(done) {
  var xhr = new XMLHttpRequest();
  xhr.onreadystatechange = function() {
    if (xhr.readyStateChange === 4) {
      try {
        var res = JSON.parse(xhr.responseText);
@wesleytodd
wesleytodd / gist:34fd31e9822e6ee567ee
Last active August 29, 2015 14:05
An example of hydrating a media url from an api response
var mockVideo = {
title: 'My Awesome Video',
public_id: 'abc123',
media: {
_links: {
thumbnail: {
template: 'http://frame.thestaticvube.com/snap/{width}x{height}/{public_id}.jpg;t={timestamp}'
},
video: {
template: 'http://video.thestaticvube.com/video/{resolution_id}/{public_id}.mp4'
(function() {
@wesleytodd
wesleytodd / angular.js
Last active August 29, 2015 14:05
Example of a very basic module
// Export for Angular
if (angular) {
angular.module('vube.video', [])
.factory([function() {
return VideoSingle;
}]);
}
@wesleytodd
wesleytodd / downloading
Created July 17, 2014 02:34
Ways to install node.js in bash
#!/usr/bin/env bash
#
# Inspired by:
# https://github.com/visionmedia/n/blob/master/bin/n
# http://stackoverflow.com/a/8597411
#
# Detect Platform
if [[ "$OSTYPE" == "linux-gnu" ]]; then