Node.js to Clojure in 60 seconds
Lumo is a neat little Clojure-to-JS compiler that runs on Node.js. Though tools like Lieningen and Boot provide incredible value (like REPL-based interactive programming), they require some legwork to get running. Lumo really shines in this aspect: it’s dirt-cheap upfront, especially if you’re already running Node.js on your system.
With Lumo, getting a ClojureScript environment running is as simple as
npm install -g lumo-cljs. Beautiful! We’re already getting to the good stuff. I’m actually gonna steal and modify this bit of code (thanks bhauman, not all heroes wear capes!) to get a basic Express app serving
GET /helloon port 3000. Note: you can pretty easily get Lumo to compile for the browser (making full use of Google’s Closure Compiler with optimizations like dead-code removal), and could even go as far as building an isomorphic React app on Lumo, but more on that in another post.
My server.cljs looks like this:
Looks familiar, huh? You’ll need Express installed to run the app, so go ahead and
npm install express.
Ok, so next, you’ll need to… oh wait, I think that’s it?
$ lumo -i server.cljs
Now, in another terminal,
curl localhost:3000/hello. Easy, right?
Lumo is incredibly fast to start up (unlike
lein repl, for example), and in the JVM-dominated Clojure world, this is a very welcome change of pace. Shell scripts and CLIs in Clojure? Why not?
Update: There is a new framework called Macchiato that enables Node.js development in ClojureScript. Check it out!