Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Off the Rails
Search
Danielle Smith
March 17, 2017
Programming
0
26
Off the Rails
My journey to becoming a
~hipster~ Node.js developer
Danielle Smith
March 17, 2017
Tweet
Share
More Decks by Danielle Smith
See All by Danielle Smith
Ruby Ruby
daninithepanini
0
140
A Brief History of Ruby
daninithepanini
0
39
Static Type Inferencing ... in Ruby?
daninithepanini
0
21
Action Game
daninithepanini
0
35
RubyGL
daninithepanini
0
26
YeSQL
daninithepanini
0
24
Game Dev in Ruby
daninithepanini
0
36
Euler vs Hamilton
daninithepanini
0
41
Other Decks in Programming
See All in Programming
iOSでSVG画像を扱う
kishikawakatsumi
0
180
マイベストのシンプルなデータ基盤の話 - Googleスイートとのつき合い方 / mybest-simple-data-architecture-google-nized
snhryt
0
130
Verilator + Rust + gRPC と Efinix の RISC-V でAIアクセラレータをAIで作ってる話 RTLを語る会(18) 2025/11/08
ryuz88
0
220
Researchlyの開発で参考にしたデザイン
adsholoko
0
110
Making Angular Apps Smarter with Generative AI: Local and Offline-capable
christianliebel
PRO
0
110
Blazing Fast UI Development with Compose Hot Reload (droidcon London 2025)
zsmb
0
460
Amazon ECS Managed Instances が リリースされた!キャッチアップしよう!! / Let's catch up Amazon ECS Managed Instances
cocoeyes02
0
130
PyCon mini 東海 2025「個人ではじめるマルチAIエージェント入門 〜LangChain × LangGraphでアイデアを形にするステップ〜」
komofr
2
400
三者三様 宣言的UI
kkagurazaka
0
350
Reactive Thinking with Signals and the Resource API
manfredsteyer
PRO
0
120
自動テストのアーキテクチャとその理由ー大規模ゲーム開発の場合ー
segadevtech
0
470
When Dependencies Fail: Building Antifragile Applications in a Fragile World
selcukusta
0
120
Featured
See All Featured
Fireside Chat
paigeccino
41
3.7k
The Cult of Friendly URLs
andyhume
79
6.7k
The Pragmatic Product Professional
lauravandoore
36
7k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
9
950
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.2k
Building a Modern Day E-commerce SEO Strategy
aleyda
44
8k
How STYLIGHT went responsive
nonsquared
100
5.9k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.5k
What's in a price? How to price your products and services
michaelherold
246
12k
Being A Developer After 40
akosma
91
590k
Making Projects Easy
brettharned
120
6.4k
Transcript
Off the Rails My journey to becoming a hipster Node.js
developer
Hi, I’m Dan
Ruby is my first love
But I got into an affair with Node.js
Temptation
Client said they had “experience”
(also didn’t seem to like ruby for some reason)
But what the heck, Node.js is the new hotness, right?
None
First rule of node.js -
THERE ARE NO RULES!
Seeing a node.js project for the first time
Controllers?
Express.js !
Models?
Find an ORM that works!
Views?
$ mkdir views $ vim views/index.jade
No Black Magic
Just raw, naked programming
Make your OWN conventions
None
“What happens server-side, stays server side” Problem?
Scenario: Developer A types in a ‘console.log’
Developer B: “where is that going to show up?”
Developer B: “where is that going to show up?” Developer
A: “in the server log”
Developer B: “where is that going to show up?” Developer
A: “in the server log” Developer B: “okay cool”
Developer B: “where is that going to show up?” Developer
A: “in the server log” Developer B: “okay cool” both devs watch the server log for some time
Developer B: “where is that going to show up?” Developer
A: “in the server log” Developer B: “okay cool” both devs watch the server log for some time Developer A: “No wait, there it is in Chrome’s devtools"
Familiar (but different)
npm / bundler
gulp / rake
ndenv / rbenv
mocha / rspec
jade / slim
Express.js / sinatra
Sequelize / ActiveRecord (almost)
factory-girl / factory-girl
Going so fast!
WHY SO SYNCHRONOUS?
Errorbacks
Errorbacks
The anatomy of an ‘errorback’ function(error, results…)
The anatomy of an ‘errorback’ function(error, results…) the result(s) of
the function taking the callback
The anatomy of an ‘errorback’ function(error, results…) this is non-null
if there was an error the result(s) of the function taking the callback
foo(42, function(err, result) { // happens “later” if (err) {
console.error(err.message); } else { console.log(result); } }); // happens immediately ...
Seems innocent enough until ...
Callback Hell
foo(42, function(err, fooResult) { if (!err) { bar(fooResult, function(err, barResult)
{ if (!err) { baz(barResult, function(err, bazResult) { if (!err) { qux(bazResult, function(err, quxResult) { if (!err) { norf(quxResult, function(err, norfResult) { if (!err) { console.log("Great Success!"); } else { console.error("Could not norf"); } }) } else console.error("Could not qux"); }); } else console.error("Could not baz"); }); } else console.error("Could not bar"); }); } else console.error("Could not foo"); });
Async Waterfall (not at all related to the development methodology)
async.waterfall([ function(cb) { foo(42, cb); }, bar, baz, qux, norf
], function(err, result) { if (!err) { console.log("Great Success!"); } else { console.error("Could not norf: " + err.message); } });
Better, but not perfect
A Promising Solution
foo(42) .then(bar) .then(baz) .then(qux) .then(norf) .then(function(norfResult) { console.log("Great Success!"); })
.catch(function(error) { console.error("Could not norf: " + err.message); });
Promises are like monads
User.find(42).then(function(user) { // returning a promise return user.getPosts(); }).then(function(posts) {
// posts is the resolved value });
User.find(42).then(function(user) { // returning a value return user.name; }).then(function(name) {
// name === user.name });
Functional.
User.find(42).then(function(user) { return user.getPosts(); }).filter(function(post) { return /Lorem Ipsum/.test(post.body); }).map(function(post)
{ return post.getComments(); }).reduce(function(total, comment) { return comment.getLikes() .then(function(likes) { return total + likes.length; }); }, 0);
Broken Promises...
User.find(42).then(function(user) { return user.getPosts(); }).then(function(posts) { // yay, I have
posts! // but where is my user? }).then(...); Bringing ‘user’ to the party
User.find(42).then(function(user) { return user.getPosts() .then(function(posts) { // yay, I have
posts! // and I have a user! )}; }).then(...); Promise Hell?
var user; User.find(42).then(function(_user_) { user = _user_; return user.getPosts() }).then(function(posts)
{ // yay, I have posts! // and I have a user! }).then(...); Klutzy variables?
var findUser = User.find(42); findUser.then(function(user) { return user.getPosts(); }).then(function(posts) {
var user = findUser.value(); // yay, I have posts! // and I have a user! }).then(...); ‘Resolved’ values?
var nizzleUserPosts = function(user) { return user.getPosts() .then(function(posts) { //
yay, I have posts! // and I have a user! }); } User.find(42).then(nizzleUserPosts) .then(...); Refactor that Shizz-Nizzle!
Regret?
None
Non-blocking means code sometimes runs off without you
The WTFs of Asynchronous-ness “I called this here and it
console.log’s there, wtf?” “Foo is happening before Bar, wtf?” “I called Bar, but it never happened, wtf?” “I never called Baz, but it’s happening, wtf?”
I’ve never missed ActiveRecord so much
Sequelize ORM
Migrations that needed to be migrated
Table “SequelizeMeta” has no column “to”
Associations that can’t associate
User.hasMany(Post); //... User.find(42, {include: Post}); //... Error: User and Post
not associated!
Source Maps while testing, anyone?
$ gulp test ... TypeError: evaluating ‘z[fn]’ /MyBlog/models/user.coffee:1:1 ... /MyBlog/models/user.coffee
1: ‘use strict’ 2: 3: module.exports = 4: foo: ->
This is not the require you’re looking for
Ruby: FooBar = require ‘foobar’ # Now you have FooBar
module # ... everywhere!
Node.js: FooBar = require(‘foobar’); // Now you have FooBar module
// ... in this file only
Circular dependency nightmares
require(‘foo’) in ‘bar’ require(‘bar’) in ‘foo’ you’re gonna have a
bad time
Sometimes I wish I could just `rails c`
Sometimes I wish I could just `binding.pry`
Acceptence
Express.js is fantastic
app.use(function(req, res, next) { // write some middlewarez next(); });
MIDDLEWARE ALL THE THINGS!
Authentication?
DB Connection?
Asset Pipeline?
`before` hook?
Middleware!
Node.js has come a long way
This ain’t yo mamma’s JavaScript
Walmart, PayPal, Ebay, Linkedin can’t be wrong, right?
Praised for its short development time
And IO performance (thanks to non-blocking)
ORMs and RDBMS support not quite there yet (IMO, don’t
quote me)
But huge NoSQL support (mongo, couch, etc)
Large, complex, enterprise-y software? maybe not
Microservices? Absolutely!
Thanks