The State of Javascript 2016

The State of Javascript 2016

Depending on who you ask, right now JavaScript is either turning into a modern, reliable language, or a bloated, overly complex dependency hell. Or maybe both?

Overall, ES6 is king, Coffeescript is done, and people are still creating new syntax/languages that will compile to javascript.

As to frameworks, I was surprised (or… maybe not?) that more people would not use Angular again (34%) than would (30%). Not surprising… (uh confimation bias?) React is hot, and developers are satisfied with it (54% would use again vs 5% would not). Also… Redux is king for state management (which looks like a React-only question. I’m not sure if other frameworks use these)

Build a Music Streaming App With Electron, React & ES6

Build a Music Streaming App With Electron, React & ES6

Electron is a framework for building cross-platform desktop apps using web technologies – javascript, HTML, CSS, Angular, React or whatever. Created by Github, it powers the Atom editor (also by Github), as well as other apps such as Slack, Hyper, and Visual Studio Code. Its a really cool piece of technology that puts a lot of power to develop desktop apps in the hands of developers who don’t have (or don’t want to) get into platform-specific desktop technologies.

zperrault/vimrc.js

zperrault/vimrc.js

A vimrc that Just Works™ for modern JavaScript development

Adds javascript, ES6, and React/JSX syntax highlighting and indentation support to VIM.

Dr. Frisby's Mostly Adequate Guide to Functional Programming

A “Mostly Adequate” guide to funcitonal programming. Going onto the reading list.

Written using Gitbook which is a really cool tool for writing online books. I wish they had a way to star or add books to a library as it is… I’ll just have to drop this link here.

Dokku + Dockerfile deployments

Dokku is a fantastic little PAAS app written in bash that can take a git push, build, and host your apps. It can use Heroku Buildpacks or Docker to build your app (and uses Docker to host your running app) and can hadle running multiple Docker containers on a single host and sets up Nginx to proxy and route requests to the correct application.

I have deployed many apps onto our Dokku hosts, mostly Node.js apps using Hapi.js, Express, as well as Java services. Recently I built a statically-rendered React application (a client-side only app without a server process doing the rendering etc; see this post for explaination) where I just wanted Nginx to handle serving the app code and assets. To do so I created a new base Docker image for serving the app just ran Nginx and ponted to my app code.

One problem with this static-rendering strategy is the issue of configuration. Depending on the environment we were deploying the app too meant we needed slightly different setups. For the test environment, we want to point to test envirnmant APIs, use production builds, while production would need to use the produciton APIs, and also would be proxied to from the getway nginx servers with a path prefix i.e. under test the app would be at http://myapp.test.dev while the production app would be at http://foo.com/myapp – there is an extra layer of nginx proxying involved in the production setup, but it also requires the production build to be aware of that extra path segment when returning URLs for assets (javascript, PNGs etc).

Where we have server process handling requests we have full control over these and use request headers to inject this configuration per request, however a static app can’t do this in the same way so we’re left with producing environment specific builds. Dokku inherently does this as every deployment (e.g. to prod host or test host) so we just need to be able to pass this configuration at build time. According to the Dokku docs “The variables are available both at run time and during the application build/compilation step” however this is only true for Heroku buildpack deployments, not Docker deployments.

To get the same thing with Docker builds we have to use the dokku docker-options command which allows us to set options for build, deploy, or run phases of the process. Under the covers the Dokku build invokes docker build which does not take the same -e parameter that docker run accepts for setting environment variables, but does have the --build-args parameter. One caveat of this technique is this requires the Dockerfile your app uses to be modified to accept build arguments using the ARG command. If you don’t specify the arg being passed with ARG the build will fail with the error “One or more build-args were not consumed”.

So to set a build argument of PATH_PREFIX in our example above:

  1. dokku build-options:add myapp build '--build-arg "PATH_PREFIX=/myapp"'
  2. modify your dockerfile
FROM baseimage

ARG PATH_PREFIX                            # declare PATH_PREFIX as build arg
RUN PATH_PREFIX=${PATH_PREFIX} ./dobuild   # use PATH_PREFIX (in this case as an env var consumed by build script)

Then commit changes and git push your app