2. Benjamin Gruenbaum
• I work @ TipRanks
• NodeJS core collaborator.
• Promises guy, bluebird fan and core contributor.
• I argue with people online.
• StackOverflow guy.
3. This talk is in 3 parts
The Past
The Present
The Future
28. The result of the io.js fork:
Modern V8 version.
NodeJS on top of the io.js fork rather than the
Joyent repo.
Handing over of the Joyent repo to the NodeJS
foundation.
Community governance.
Lots of new features for the community.
30. Current version: Node 7+
Node 0.12 – last year
function persistCriticalFile(cb) {
fs.readFile("criticalFile", function(err, data) {
if(err) return cb(err);
db.persist("collection", process(data), function(err, result) {
if(err) return cb(err);
cb(null, result);
});
});
}
31. Current version: Node 7+
Node 7 – this year
async function persistCriticalFile(cb) {
const data = await fs.readFileAsync("criticalFile");
return await db.persistAsync("collection", process(data));
}
32. So – how do we develop with Node 7?
Let’s look at a simple scenario. You want to get the comments to a post
on your site.
- First, from the cache if they’re there.
- If they’re not, from the database.
33. So – how do we develop with Node 7?
Node 0.x:
app.get('/getComments/:userId', function(req, res){
var userId = req.params.userId;
commentCache.get(userId, function(err, data) {
if(err) {
instrumentation.log(err);
return res.json(err);
}
if(data) return res.json(data);
db.getCommentsByUserId(userId, function(err, data) {
if(err) {
instrumentation.log(err);
return res.status(500).end(err);
}
cache.store(data, function() {});
return res.json(data);
});
});
});
34. So – how do we develop with Node 7?
Node 0.x:
app.get('/getComments/:userId', function(req, res){
var userId = req.params.userId;
commentCache.get(userId, function(err, data) {
if(err) {
instrumentation.log(err);
return res.json(err);
}
if(data) return res.json(data);
db.getCommentsByUserId(userId, function(err, data) {
if(err) {
instrumentation.log(err);
return res.status(500).end(err);
}
cache.store(data, function() {});
return res.json(data);
});
});
});
35. So – how do we develop with Node 7?
Node 0.x:
app.get('/getComments/:userId', function(req, res){
var userId = req.params.userId;
commentCache.get(userId, function(err, data) {
if(err) {
instrumentation.log(err);
return res.json(err);
}
if(data) return res.json(data);
db.getCommentsByUserId(userId, function(err, data) {
if(err) {
instrumentation.log(err);
return res.status(500).end(err);
}
cache.store(data, function() {});
return res.json(data);
});
});
});
36. So – how do we develop with Node 7?
Node 0.x:
app.get('/getComments/:userId', function(req, res){
var userId = req.params.userId;
commentCache.get(userId, function(err, data) {
if(err) {
instrumentation.log(err);
return res.json(err);
}
if(data) return res.json(data);
db.getCommentsByUserId(userId, function(err, data) {
if(err) {
instrumentation.log(err);
return res.status(500).end(err);
}
cache.store(data, function() {});
return res.json(data);
});
});
});
37. So – how do we develop with Node 7?
Node 0.x:
db.getCommentsByUserId(userId, function(err, data) {
if(err) {
instrumentation.log(err);
return res.status(500).end(err);
}
cache.store(data, function() {});
return res.json(data);
});
});
38. So – how do we develop with Node 7?
app.get('/getComments/:userId', ({params: {userId}}, res) => {
const fromCache = await commentCache.get(userId);
if(fromCache) return res.json(fromCache);
const fromDb = await db.getCommentsByUserId(userId);
res.json(fromDb);
commentCache.store(userId, fromDb);
});
39. How our flow has changed: tests
Old
it("does something", function(done) {
myApi("someData", function(err, result) {
assert.equal(err, null);
assert.equal(result === 3);
done();
});
});
New
it("does something", async () => {
assert.equal(await myApi("someData", 3));
});
40. How our flow has changed: classes
Old
function User(id) {
this.id = id;
}
User.prototype.foo = function(id){
doBar(id);
}
New
class User {
constructor(id) { this.id = id }
foo() { doBar(id); }
}
41. How our development flow changed.
• Hot reload servers in JS
• Node first approaches in client side flows
• The rise of universal JS
42. How our web flow changed.
• Rest vs. GraphQL/Falcor.
• Native debugger.
• Handling request/response cycles.
• How express changed.
• How clustering changed.
43. How production changed.
• The rise of containers.
• More people into node.
• Community got a lot bigger, a lot more mature.
• Node backed by major companies.
• Node for IoT, node on Chakra.