How do I launch a clojurescript nodejs REPL outside a project structure?

Does anyone know a way? There was lumo, but it’s not maintained anymore.

Here is an example which also includes a library to play with in the Node.js REPL:

clj -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "1.10.597"} funcool/promesa {:mvn/version "6.0.2"}}}' -M -m cljs.main -re node

The clj command is the Clojure CLI tool.

1 Like

Is there something more polished? I feel that clojurescript REPL needs its own executable.

For users of VS Code an easy way to fire up an editor connected ClojureScript Node REPL is to use Calva’s command for it:

https://calva.io/getting-started/#there-are-standalone-clojurescript-quick-start-repls

There’s also Planck: https://planck-repl.org/ though it uses JavaScript Core instead of Node and is Mac and Linux only.

1 Like

I specifically need to use NodeJS because I want to utilize npm packages interactively on clojurescript REPL.

Planck is dead, by the way. GitHub - mfikes/ambly: ClojureScript REPL into embedded JavaScriptCore is less dead if you want JavscriptCore clojurescript REPL.

I think a hack is to create an executable that executes

clj -M -m cljs.main -re node

in a clojurescript project folder.

You can just add yourself a shell alias if you want a short command.

in .bashrc or .zshrc:
alias noderepl='clj -M -m cljs.main -re node'

Also, I don’t think planck is dead, I think Amby is different, its not the newer planck, planck used to use Amby under the hood but then the objective-c was rewritten to portable c to support linux.

Another way to do it is

~/.config/deps.edn

{:deps {org.clojure/clojurescript {:mvn/version "1.10.xxx"}
        funcool/promesa {:mvn/version "x.x.x"}}}

~/.local/bin/cljs-node-repl

#!/bin/sh
deps=`cat ~/.config/deps.edn`

clj -Sdeps "${deps}" -M -m cljs.main -re node

You need to go read about the deps.edn aliases, you’re making this way more complicated.

See: How to turn `clj -m cljs.main` into a single command line? - #2 by alexmiller

If you want to try out Node.js libraries with a light-weight CLJS scripting environment, you can also try out the brand new GitHub - borkdude/nbb: Ad-hoc CLJS scripting on Node.js.. REPL not yet implemented, but in the future there will probably even be nREPL support.

2 Likes

I think that’s a way.

@catdog why exactly you are avoiding a project structure? Seems that a simple node-script shadow-cljs target is perfect for what you want…

Because a projct structure is not needed for a quick REPL session.

Where will those npm packages be located? Will there be a package.json? If so you could npm install shadow-cljs there and put a shadow-cljs.edn in the same directory (potentially just {}, if you don’t need any CLJS related config). That is about the bare minimum “project structure”. You’ll probably want to add :source-paths and :dependencies at some point but :builds you don’t need if you just want to REPL.

npx shadow-cljs node-repl will then give you a quick and easy node REPL without too much work?

How to turn `clj -m cljs.main` into a single command line? - #2 by alexmiller is a better way to do things outside project structures.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.