You're viewing all posts tagged with node

How I hack on node apps

splitw

First, there’s my ‘splitw’ command, which I use to run long-running process in a split screen.

Code on github

XRefresh

Then, there’s the XRefresh extension for Firefox. It requires a separate server. Check it out from github: https://github.com/YouWoTMA/xrefresh-server then create a symlink to the xrefresh-server (an executable python script).

I run it like this:

xrefresh-server -e ".git/" .

Supervisor

And also, there’s ‘supervisor’ node package; it runs js (or coffee) files and watches them automatically; when they change, it restarts the server.

Install it from npm:

npm install supervisor

Assumptions

I assume the app’s starting is always server.js (this is actually because of the webbynode hosting). And I assume there’s a git repo that I want to constantly work with as I hack.

I can still write the app in coffee-script, just have to make server.js look kinda like this:

require("coffee-script")
require('./app.coffee')

And then I have to pass -e "coffee|js" to supervisor so that it also watches .coffee files for changes (by default it only watches files with .js or .node extensions).

Putting them together

So here’s a simple command:

splitw 'supervisor -e "coffee|node|js" server.js' 'xrefresh-server -e ".git/" .' 'bash'

This splits the terminal to 3 horizontal panes, the first running the ‘supervisor’ node reloader, the second running xrefresh-server, and the last one just a normal shell so I can create git commits.

hack hack hack

I save that command to ~/bin/gonode and so when ever I want to hack on some node app,

~$ cd code/<app>
~/code/<app>$ vim server.js

Then hit ctrl-shift-t to open a new tab (it inherits the current working directory), and in it:

~/code/<app>$ gonode

And it will fire the server, the firefox refresher, and leave a pane for the shell.

The screen split kinda looks like this: