Before we begin, make sure you can start a node.cljs repl first.
One important thing I want to highlight is that you should have a stable version of node 0.12.X as the linked wiki page says. Additionally, you want to make sure you have npm installed so you can install node packages later on. Finally, I'm also assuming that you already have Clojure and Clojurescript setup with Leiningen.
Start by making a new leiningen project.
lein new node_project
And then move into that directory.
Start by editing your project.clj file to look something like this:
It's very important that you use versions of Clojure and Clojurescript greater than or equal to the ones I've listed. I've ran into a lot of issues trying a setup like this before finding one that worked. It was mostly due to old versions of piggieback and Clojurescript.
I added the piggieback related dependencies in dev for the node.js REPL we're going to be using later. The clean-targets are for the command
Because cljsbuild deprecated its clean function.
A few more things to note:
We're using no optimizations and targeting node.js. Having optimizations set to :simple, I ran into issues with core.async macros.
Next, we need to setup the node side of the project. Inside the same project folder, run:
You can pretty much press enter for every single prompt, except the entry point one. There you want it to be named app.js, not index.js as we specified in the project.clj. We can't run index.js directly due to optimizations being set to none, so cljsbuild will output multiple files.
Next, you can install a web framework using npm like express:
Now that we have Express.js installed, we can just make a simple hello world web application in clojurescript.
Rename src/node_test/core.clj to src/node_test/core.cljs.
Then in the file put this:
Now that we have our index.js file, we need to make the file for node to run the application.
Make a file called app.js in the root of your project folder with this as its contents:
If you've changed anything, replace the paths with the correct one.
Now, you can start the app with node.js:
And if you visit that url, you'll receive an error message about not being able to GET /. That's fine, we didn't specify any routes.