Fork me on GitHub

If I start my server with clojure -A:dev:xtdb -M -m com.example.components.server, how do I connect to that same REPL? For example, if I want to inspect the (mount/running-states).


here's how to start one with mount:

      [ :refer [config]]
      [mount.core :refer [defstate]]
      [nrepl.server :refer [start-server stop-server]]))

  (defstate nrepl-server
    (let [{keys [port]} (::config config)]
      (start-server :port port))

    (stop-server nrepl-server))
(and of course add the dep and include this ns in your server entry)

gratitude-thank-you 1

Or use the socket repl, so you don't need nrepl if you wouldn't use it otherwise


I would use clj -Sdeps '{:deps {nrepl/nrepl {:mvn/version "0.9.0"} cider/cider-nrepl {:mvn/version "0.28.3"}}}' -m nrepl.cmdline --middleware '["cider.nrepl/cider-middleware"]' --interactive if nrepl is needed sometimes, instead of adding code for it.


@U8ZQ1J1RR so first I would launch my server and then use that command to access the nrepl? I'm doing that and it still doesn't seem to be the same REPL as my running server.

$ clj -A:dev:xtdb -Sdeps '{:deps {nrepl/nrepl {:mvn/version "0.9.0"} cider/cider-nrepl {:mvn/version "0.28.3"}}}'  -m nrepl.cmdline  --middleware '["cider.nrep l/cider-middleware"]' --interactive
WARNING: Implicit use of clojure.main with options is deprecated, use -M
nREPL server started on port 42755 on host localhost - 
nREPL 0.9.0
Clojure 1.10.3
OpenJDK 64-Bit Server VM 11.0.15+10-Ubuntu-0ubuntu0.20.04.1
Interrupt: Control+C
Exit:      Control+D or (exit) or (quit)
user=> (use '[mount.core :as mount])
user=> (use '[com.example.components.server :as server])
2022-05-04T18:46:31.120Z ubuntu-focal DEBUG [com.fulcrologic.rad.blob:197] - Wrapping persist-images with image keys #{}
user=> (mount/running-states)
Or do you mean that I should add that to my current launch command when starting the server?


Yes, you cannot bolt on a repl on a different process. But you can launch it purely on command line without making code changes


Okay, that's a useful option indeed if I'm just using the REPL occasionally to debug stuff. Thank you for the tip. I wonder, is using the REPL a common thing in production?


I don't think so, but that's just what I hear in the local bubble. Sean Corfield is a big proponent of repl in production, and I think they have the socket repl always running


This handy practicalli repo has an defined for exactly what you suggested @U8ZQ1J1RR. Along with a few other useful ones that are related. Posting here for reference.


Yeah, some people like to have a global alias. I just dig it from shell history ๐Ÿ™‚


Fulcro (nor itโ€™s templates) do not, by default, install an nREPL server.