#JavaScript #Node #ES6 #architecture

Simple, but not too simple: how using Zeit’s `micro` improves your Node applications

Leave the Express comfort zone to expand how you think about Node application architecture. tl;dr using a function composition model for building HTTP servers is awesome Functions as a Service are great but have some drawbacks micro has a similar, simple API to FaaS but doesn’t have a compilation step micro’s minimalism affects how you solve problems Functions as a composition model for JavaScript Functions as a Service pain points ...

  • Hugo Di Francesco
    Author
7 min read
#JavaScript #ES6

Use ES modules in Node without Babel/Webpack using `esm`

Node has been implementing more and more ES6+ (ESNext) features natively. One of the features that is taking the longest to implement is modules. The reason for this is that Node and npm run on what is called CommonJS, with which you use require('module-name') to import from other modules and use the module.exports object to expose entities from a module. Node’s CommonJS was actually one of the first widely adopted module systems in JavaScript. ...

  • Hugo Di Francesco
    Author
3 min read
#JavaScript #ES6 #interview #functional programming

Impress interviewers with recursion in JavaScript with ES6 features

There’s nothing as flashy and useful for JavaScript interviews than recursion. If you just want to be impressive with recursion in JavaScript, here are some semi real-world (technical test type) examples. The short definition of a recursive solution to a problem (in computer science) is: don’t use iteration. This usually means a function has to call itself with a smaller instance of the same problem until it hits a trivial case (usually defined in the problem). ...

  • Hugo Di Francesco
    Author
4 min read
#Testing #JavaScript #ES6

Abusing Jest snapshot tests: some nice use-cases 📸

There’s some nice use-cases for snapshot tests outside of the well-travelled React/Vue UI component ones. In other words, although React and Vue testing with snapshots is pretty well documented, that’s not the only place they’re useful. As a rule of thumb, you could replace a lot of unit tests that assert on with specific data with snapshot tests. We have the following pros for snapshot tests: - the match data is stored in a separate file so it’s harder to lose track of things, eg. ...

  • Hugo Di Francesco
    Author
6 min read
#JavaScript #ES6 #web development

Recursion in JavaScript with ES6, destructuring and rest/spread

The latest ECMA standard for JavaScript (ECMAScript 6) makes JavaScript more readable by encouraging a more declarative style with functional constructs and new operators. Destructuring One of my favourite ES6 features is destructuring. It allows you to extract data from one variable to another by using structure. For arrays this means for example: var [first, second] = [1, 2, 3, 4]; // first: 1 // second: 2 There’s more you can do, like skip some members of the array on the right-hand side of the operation. ...

  • Hugo Di Francesco
    Author
6 min read