How to write frontend (reagent) and backend (express.js) applications in a same clojurescript setup?


Can I write frontend (reagent) and backend (express.js) applications in a same clojurescript project?

Following these two pages.

  1. Writing Node.js applications in Clojure and using NPM packages Backend (express.js)

  2. shadow-cljs Frontend (reagent, react)

Both of them are similar, create a new cljs project with npx create-cljs-project {project-name}. However, these are two individual projects, can I write frontend and backend application in a same project, if it is possible, how to manage repl in this project?


Sure, the entire system is designed to combine as many things as you like. Just configure multiple builds in the shadow-cljs.edn :builds map.

If you already have both separate projects just take the .cljs files and move them to the other. Then take the build config and also move it into the other shadow-cljs.edn.

You may either control multiple builds from the shadow-cljs UI or the command line. All build relevant commands allow you to specify multiple builds (eg. npx shadow-cljs watch backend frontend, with the :frontend and :backend builds in shadow-cljs.edn).

You can use namespaces to properly "categorize" your project. I generally have something like or for frontend related things and something like or

With the watch for both builds running you can just switch between the REPLs in your editor. From the command line you can just npx shadow-cljs cljs-repl frontend or npx shadow-cljs cljs-repl backend. Or switch between them from a Clojure REPL via npx shadow-cljs clj-repl and then (shadow/repl :frontend). That’ll bring you into the CLJS REPL for the :frontend build. You may exit that via :cljs/quit, which brings you back to the CLJ REPL.

Answered By – Thomas Heller

Answer Checked By – Mary Flores (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.