IT IS HERE! Get Smashing Node.JS on Amazon Kindle today!
Show Posts
← Back to homepage

Last night I wrote a tiny up middleware to enable zero-downtime reloads of the code that powers your HTTP server whenever you push to a GitHub repo: up-hook.

Back when I introduced the project, I mentioned that it could be used both from the CLI and programmatically. The advantage of the latter, of course, is that since up is a layer of abstraction on top of distribute, one can write middleware that can alter its behavior.

For those not familiar with post-receive hooks, the concept is pretty simple: you set up a URL that GitHub sends a HTTP POST request to every time you push to the repository.

Its usage is really straightforward:

srv.use(uphook('/super-secret-url', { cmd: 'make deploy' }));

By default, it’ll capture hooks to the branch master and execute the given cmd, which defaults to git pull. All there’s left to do is to configure your GitHub repository:

You can find this in your project administration

As usual, head to the GitHub page for more information. You can find the project as up-hook in NPM.

I rarely have the need to generate man pages for a project, but I realized they could be useful for spot(1). For those situations, the solution by TJ Holowaychuk is one curl and handy Heroku-hosted web service away:

curl -s -F > file.1

In my computer and slow connection at home, it took 1 second to run this task as measured by time(1). Not bad for something that was already in my computer (curl), that prevented me from needlessly having to run the easy_install/npm/gem/brew/package manager of the day.

As a matter of fact, while installing a Python CLI utility the other day, I pressed tab to autocomplete and was met with a few options:

∞ easy_install
 easy_install      easy_install-2.5  easy_install-2.6  easy_install-2.7

The reality is that a lot of the tools we use or could be using in our terminals could be run somewhere else, and their installation could consist in setting up an alias in your bash profile. Do you need to do syntax highlighting but don’t care for installing a bunch of things?

alias pygmentize="ru pygmentize"

My suggestion here is the creation of a ru command (codename remote unix) whose job would be to provide the same interface as the original command, but execute it remotely. If you pass it -h to get help, it takes that to the web service and outputs its response.

Other examples of potentially useful cloud-run tasks include any text compilers (eg: mantastic, markdown, textile), file type conversion and manipulation (eg: png2gif, trimage), and more.

With the announcement of SPDY support by Twitter, I thought it would be cool to visualize how this extends to the rest of the web as I browse it.

I developed a Chrome extension you can install to visualize SPDY support in your address bar. Source on Github.

Install Chrome Extension

For those who haven’t heard of SPDY, it’s a new protocol being developed by Google to transport the existing HTTP protocol more efficiently (up to 50% faster). You can read more details in the official Chromium page.

Read more

spot is a tiny file search utility written in Bash, meant to be fast and have very straightforward usage.

For example, it considers all your arguments to be the search phrase without needing quotes:

And it turns on case-sensitive search if you include an uppercase letter:

The aim of the utility is to be useful and straightforward for the majority of searches. Hence, its options will always stay limited and the codebase brief. You’re also encouraged to fork it and modify it to your liking!

Go to the GitHub project page for download, examples and the up-to-date project.

I created a tiny yet useful shell script that opens a browser window on the GitHub “new pull request” interface.

Add the following to your bash profile and run it as pr. It will detect the user, repository and branch automatically.

function pr () {
  local repo=`git remote -v | grep -m 1 "(push)" | sed -e "s/.*[:/]\(.*\)\.git.*/\1/"`
  local branch=`git name-rev --name-only HEAD`
  echo "... creating pull request for branch \"$branch\" in \"$repo\""

export -f pr

Socket.IO 0.9.0

Socket.IO 0.9.0 has been released, and it’s packed with bug fixes and performance/stability enhancements on both the server and client codebases.

Please refer to the mailing list announcement thread for a detailed changelog.

This also puts us in the last sprint to Socket.IO 1.0! Stay tuned in the coming weeks for the appropriate announcement.

Up 0.1.5

When you use the up CLI for zero-downtime HTTP reloads, you can already leverage --watch to reload your server while developing based on configuration file changes.

However, sometimes things change that are not captured as easily, like configuration files, caches, environment, etc. For this, you can now press ctrl + R in the comfort of your terminal to trigger a quick reload.

 ∞ hello-world (master) up server.js 
  up-cli starting cluster with 1 workers on port 3000
  up-cli `kill -s SIGUSR2 76715` or ctrl + r to load new code
  up spawning 1 workers from master 76715
  up worker 76716 created
  up worker 76716 listening on port 60995
  up-cli ctrl + r detected - reloading
  up reloading - spawning 1 new workers
  up spawning 1 workers from master 76715
  up worker 76718 created
  up worker 76718 listening on port 60997
  up worker 76718 spawned - removing old workers
  up telling worker 76716 to exit in 500ms
  up worker 76716 exited 

WebSocket.IO 0.1.6, Distribute 0.1.4

Maintenance releases for these two modules.

The Node.JS websocket server with support for all protocols and parsers gets a maintenance fix for 0.4. WebSocket.IO powers the upcoming Socket.IO realtime core, Engine.IO.

Distribute 0.1.4 adds a guard to aids with the debuggability of a “double-callback” situation that can result in calling next twice within a middleware.

About Guillermo Rauch:

CTO and co-founder of LearnBoost / Cloudup (acquired by Automattic in 2013). Argentine living in SF.