web analytics

An(other) interview with Ev Bogue about Node.JS

I recently had an interview with Ev Bogue that was talking about his The Client List, and various other activities that he’s doing in his life. This included the book he’s writing about Node.JS. One of the things that I enjoy is exploring technology, and while some of you aren’t that interested, I know some of you are. So after discussing it a bit with Ev, we decided to do a follow-up interview about node.js.

If you’re one of those whose eyes glaze over as soon as someone starts talking about coding or programming or technology, then I recommend you go watch some TV right now, ’cause your eyes are about to glaze over!

Alan: Hi Ev, thanks for coming back. Now, just to be clear, I’m not interested in node.js and I haven’t read your book. I’ve also ignored your requests to code my own apps to run on my own servers, ’cause it’s just not the kind of thing I’m into at the moment. But what I AM interested in is supporting you and your efforts, and so I’m quite happy to talk to you about node.js and get your thoughts about it out there in the internet wilderness. Well, at least on my blog…. Maybe it’ll help boost your sales and you can get back to traveling again! That would be a win-win for both of us.

So what is node.js? I know it’s a version of javascript, hence the .js bit. But what does it do? What’s it good for? And why does it excite you so much?

ebpunchEv: I hope everyone’s eyes glaze over this, because I don’t want anyone to learn anything that I don’t know so when the next wheel turns in technology I’ll be the only person everyone calls. Because what is The Web than a bunch of programs, old and new, strung together across the world? Hence the WWW.

Node is just one way of programming web servers, and it does that with JavaScript. What Node does is takes the ‘V8’ JavaScript that is the same engine that parses JavaScript in Chromium and applies that to the server. There are a couple of other ways to program servers, but Node works best for the way my brain works so I’ve stuck with it even after a brief break to attempt to learn Haskell during 2014.

Let’s say I want to create a very basic application that tells anyone who visits my website ‘Hello World!’. I’d use the following code to do it in Node

var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World!\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');

And if I save this file and run it on a server with the command

% node app.js

I’ll be running a web server the echos the string ‘Hello world!’ to anyone who visits the website at the port ‘1337’.

That’s just the beginning. The reason I’m interested in Node is there’s always potential. If only I can figure out how to harness it and make that potential into something real.

Alan: Ok, I’m curious about why node.js is better than PHP, when I can get the same output from this PHP code:

<?php Echo "Hello, World!"; ?>

Why is your node.js code better than PHP, when it’s so much more complicated than PHP to get the same output? Please explain for idiots like me.

Ev: I hesitate to proclaim that Node is worse or better than PHP. You can print ‘Hello World!’ in any programming language. The reason you start with Hello World is it’s the simplest possible way to get started with the language you’re playing with, not because you want to compare ‘Hello World!’s to see which one is better.

The interesting thing about Node.js is it is the language and the web server, whereas with PHP you’re going to need a web server to compile and serve your PHP code. So you’re programming the webserver with JavaScript instead of running PHP code with a webserver. Both will get you ‘Hello World!’ in a browser of course.

Alan: I think I understand. So Node.js has everything you need all combined within it, whereas PHP and other languages have dependences on other things?

Ev: Not quite. Node.js depends on V8, which is another program, to parse JavaScript, but it provides a JavaScript API that gives you the tools you need to program a web server using JavaScript. Then Node combines the JavaScript engine with the CommonJS module loading system, and a decent package manager. This makes it easy to modularize your application, leading to a thriving ecosystem of modules that anyone can use to build applications with. In a Node.js app you’ll first ‘require’ a module at the top of the program, let’s say Koa.

var require = ('koa');

Next fire the module up.

var app = koa();

And have the application do something.

app.use(function *(){
this.body = 'Hello World';
});

Finally have it listen on a port.

app.listen(3000);

Now we have the same ‘hello world’ app from above, but this time using the Koa next generation web framework.

At this point all you need to do is install the module using `npm` from your command line.

% npm install koa

And you’re ready to roll by typing and visiting http://localhost:3000/ in your browser.

% node app.js

Alan: So what kinds of things have you created with node.js?

Ev: At the moment my website at evbogue.com is generated using Node.js as a static website, and I have a tiny Koa.js application that accepts input and emails it to me using Nodemailer.

Alan: And what do you see in the future for node.js ?

Ev: Oh man, the future of Node.js. Right now there are all sorts of politics around the future of Node.js, there have always been. The current Node.js master branch is effectively abandoned, and all of the development is happening on the io.js branch. The io.js branch is supposed to be becoming the new Node.js branch. So in the future I can speculate that eventually io.js will become Node.js. That much is somewhat certain. As for what Node.js will be capable of, that’s more up to the people who start coding with the modules and figuring out what the potential of Node.js is for yourself. I take it one day at a time, one module at a time, and try to put together little programs until I begin to understand how everything works together. For example, with the Koa Mailing app I have, I started learning Koa.js and then I thought to myself: what if I hook this up to Nodemailer with a form on the front-end? Eventually after banging my head up against it for long enough I figured out how to do something with both of those Node modules.

Alan: Earlier you were saying that Node takes the V8 javascript is used in Chromium and applies it to the server… does that mean that the server becomes a web app instead of a web app running on the server?

Ev: JavaScript grew up in the web browser, so the interesting innovation behind Node.js is it takes JavaScript to the server side of the equation. The confusing part is that in the programming world the word “server” is used within a lot of contexts. For example, you might fire up a Node.js server inside of a Virtual Private Server, which is a server within a server, the VPS of course is a virtualized server within a rack of physical servers in a server room somewhere.

A web server stack might look something similar to this in the modern era:

Physical Server > Virtual Private Server > Node.js Server

This way you’re opening your application up for a “Client” to visit the “Server” using a web browser. Node.js is in the world of interactive web servers, with buddies such as Ruby on Rails and Go as contemporaries. There’s probably others as well. And is a close cousin to the ‘static’ web server of yesteryear that was only able to serve up static HTML, CGI-BINs and PHP code.

For many people this means a slight stack upgrade. If you’re using ‘shared hosting’ with your web hosting provider, then you’ll need to switch up somewhere that provides virtual private servers, because you can’t run code (other than PHP) in a shared hosting environment. The good news is that VPS’s have gotten very cheap over the past few years. I’ve seen them anywhere from $0.99 to $10 per month.

I don’t cover how to operate a VPS in The Node.js Book, however I wrote another technical book at the beginning of 2015 called Operator’s Manual which covers the virtual private server theory as well as practice.

Alan: So what is it that excites you about Node.js? Can you summarise all of the above in a way that really digs deep and explains why this makes you wake up each day with excitement?

Ev: I got stumped by this question for a bit, but then I realized it was because Node.js doesn’t excite me at all. Instead I find myself in an endless challenge with it. I’m always trying out a new module or trying to get it to do something new. Six years ago when Node.js was first being developed there was a lot of enthusiasm about it, but I’ve found that’s given way to practicality. If you watch the master branch of io.js for any length of time, you can see they’re just trying to keep up with the latest version of V8 and trying to get Node.js to a stable version.

You’d think not being enthusiastic would be enough to send me back to thumbing an iPhone screen, but I’m too far down the rabbit hole now to go back to that. I can’t spin up tiny servers on a dumb locked-down computer. But programming is a frustrating experience for everyone involved. To get code to work, I have to bang my head against my terminal window over and over all day long until something works. This isn’t exciting, but when something works I get to feel accomplished for a brief moment in time.

Alan: And on a final note, why should people buy your books on node.js and coding? What’s in it for them?

nodeEv: The reason to buy any of my technical books is the reason anyone should ever buy a technical book, because you’ll learn a skill faster than you would figuring it out on your own. Learning to program is an endless battle against frustration and technical debt, but when my clients have breakthroughs they always email me saying ‘oh my god, I just figured X thing out look at my server!’ in many different words. So, that is why I keep writing technical books. Beyond that, it’s hard to argue with code because it does something tangible.

Alan: Ev, once again, thank you so much for your time with this interview. I hope a few more people know what Node.JS is now, and that they’re intrigued enough to buy your book. All the best.

As for you, since you’re still reading this, go buy his book here. You’ll probably love it!


Thanks for reading! Please add your own thoughts below.



Don't forget to subscribe for new posts sent to you by email!

%d bloggers like this: