Nick olus

Read this first

Writing a REST API with Hapi.js

Coming from a Python background, there were a couple of different solutions for web frameworks. Some were more of the “batteries included” persuasion, while others were extremely light weight and required you to piece together different libraries. Naturally there are two camps in this situation, those who trust in the monolithic frameworks to do all the heavy lifting and those who do not and want to include only small pieces that they choose.

But, I digress. Let’s take a look at one of, in my opinion, the latter frameworks - which is hapi. hapi is an open source project written by the super smart folks over at Walmart that defines it self as:

“hapi enables developers to focus on writing reusable application logic instead of spending time building infrastructure.”

Today we are going to build a simple blog REST API using the hapi framework and some other various libraries as well

Continue reading →


Understanding ES6 Generators

In my attempt to keep on top of the newest features coming to the land of JavaScript, I will be writing a series of posts about the features that most interest me. Not that all of them aren’t interesting, but some are super awesome.

Generators are not an entirely new concept to the world of computer science and I had some previous familiarity with them in Python. Generator functions are defined by MDN as:

Generators are functions which can be exited and later re-entered. Their context (variable bindings) will be saved across re-entrances.

Let’s take a step back and talk about a regular function. As we know it a function accepts arguments and executes until it either reaches a return statement or some sort of exception. Also in JavaScript we have a special case where we don’t provide a return statement and the function will implicitly return undefined (but that’s not worth diving

Continue reading →


Hoisting

One of the tricky concepts that stumps newcomers to JavaScript is hoisting. Even seasoned developers coming from other languages can be bitten by this feature. In most C based languages developers are used to the concept of block based scoping versus function based scoping. The best way to understand how hoisting works is by example:

function foo() {
    bar()
    baz()
    var bar = function() {
        console.log('Hello')
    }
    function baz() {
        console.log('World')
    }
}

foo()

So we have two different types of hoisting happening here, variable hoisting and function declaration hoisting.

What happens in this case is the variable bar is hoisted to the top of the function body and will return as undefined because at the time of it being called we have not assigned it to anything. Differently, the function baz is hoisted up the entire function body intact, so it

Continue reading →