Fork me on GitHub
#nbb
<
2023-07-26
>
20:07:40

Using nbb to explore an API. I'm getting response data, converting it from json to edn via js->clj, and pprint'ing it. However, unlike js/console.log the output is all in one line in the repl. Guessing in some part due to my editor of choice, but is there a way to get the formatted output to show in the nrepl server process like js/console.log?

20:07:46

perhaps you can try (set! *print-fn* js/console.log) or so?

20:07:58

Ooh will try

20:07:47

doesn't seem to work

20:07:42

user=> (alter-var-root #'prn (constantly js/console.log))
#object[log]
user=> (prn 1)
1
nil
user=> (prn #js [1 2 3]))
[ 1, 2, 3 ]
nil

20:07:01

Oh... wait I was using clj->js instead of js->clj 😵

20:07:02

It would still be helpful if println, prn, pprint, etc... could output to the main nrepl server proc like js/console.log does but this is a big improvement at least 😅

20:07:19

Ooh actually, I can write a userland function for that. Would just call with-out-str to pprint my data, then console.log the str output

20:07:52

Thinking it would be nice for keeping particular data visible on my terminal that doesn't update frequently

20:07:47

It works!

🎉 2
22:07:20

Is it possible to invoke nbb scripts from a parent directory and possibly tools like Shadow CLJS without having to run shell commands? I am investigating using nbb to unify some build tasks in a pure CLJS project, and I would like to avoid makefiles and shell scripts if I can.

08:07:56

Sure, you can use load-file in nbb and also you can use the Node libraries for spawning programs