Fork me on GitHub

Hello, can anyone help me with opening a new window using ClojureScript? I am new to JavaScript interop and I've created a question on SO regarding the problem I face with the solutions I have tried I made it work once and can't seem to make it work again. 😞 Let me know if I need to provide any more details.


Hey, I think you need something like this:

(.hello js/window) ;; JS output: window.hello();
I'm no CLJS expert, but the interop seems to work the same way as the Java one. So (.methodYouWantToCall objectYouWantToCallItOn) Source:


Thanks! Yeah, the syntax was right to being with. When I started trying with set! I overrode the open function with a string :woman-facepalming: Silly mistake.


I am trying to call an http endpoint in a Clojurescript code targeting node.js (not browser). It is supposed to be a basic thing, but I haven't found an easy way to do it, nor libraries to use. What is the idiomatic way to make a http request in a node.js backe end cljs code?

Jimmy Miller16:11:24

@dennisa You can basically do it all the same way you would with just vanilla node. So it depends on what you are wanting from the api. If you don't want to pull in anything, just use the node https library. If you want something higher level, you can use something like axios or node-fetch.


This is a working sample of my code. Works properly as I expect when I call this function from browser console but when I call same function with same data from another CLJS file It gives error.

Uncaught TypeError: Cannot read property 'push' of undefined
    at Object.spill$app$sockets$push [as push] (sockets.cljs:59)


I am trying to solve this problem since morning I have no idea why it's different from browser console or from cljs.

Jimmy Miller16:11:46

What creates the channel? Are you sure it exists when that function is run? (I have no context. so not sure if get makes the channel itself)


if I had to guess you are missing a desctructure

👍 4

(defn channel [channel_name]
  (go/get (.-channels js/window) channel_name))
this how I create


the :socket-push probabnly misses (fn [[channel event body]] ...)

👍 4

ok i'll try to figure out thank you very much


thank you very much it works 🙂🍺


is there a way to run multiple simultaneous figwheels? I have two cljsbuilds that I would like to run at the same time instead of having to (switch-to-build :build-name)


This might be a job for :extra-mains

Daniel Keane19:11:17

I assume you’re using lein-figwheel. You can run both builds by using: (start-figwheel! :build1 :build2) or do the same from the command line with: lein figwheel build1 build2


Thank you. that seems to work.

Aleks Abla20:11:47

Hi everyone! Hope you are all having a great day. I am a novice programmer, who recently picked up Clojure. It's been a lot of fun, and I have started playing around with ClojureScript and Re-Frame. I am having trouble wrapping my head around the interplay of routers, data stores, views, handlers and subscriptions. I understand what each one does theoretically, but I am shaky on how each interacts, especially as the app listens to the user and adapts. Could anyone recommend good resources to for me to look at? I am trying to build a single page application, that would act as a dashboard with basic statistics. Further down the line would love to add graphs and whatnot. these are what I have researched so far:


this is very good source i learnt mostly from here


re-frame course was expensive but I read this source commit by commit read all the changes in every commit and see what it produced ->

Aleks Abla20:11:44

Awesome, I checked out the trial of the course. Will read through the changes, thanks!


Actually I can say I learn't most of without even finishing every commit. Btw clojure community most helpful friendly community I2ve ever seen in my life ask anything in beginner channel everyone is eager to help 🙂


@jimmy I found some code node request library, but it returns #object[Request [object Object]] which I don't know how to parse easily. Have you or some has a code example of using node https libraryin cljs?

Jimmy Miller05:11:26

The https node library is a little complicated. But here is an example of node-fetch.

(ns my-app.core
  (:require ["node-fetch" :as fetch]))

(-> (fetch "")
    (.then (fn [res] (.json res)))
    (.then (fn [json] (println json))))


Thanks! I tried this before as well. What I am getting back is a #<Promise[~]> and no matter how I apply .then to it it's still returning a promise back, not the value itself.

Jimmy Miller20:11:39

Yes, that is how promises work. You cannot get out the value itself.

Jimmy Miller20:11:21

You use the then to get at the value and do something with it. Assign it an atom, send a request, etc. This is part of js being asynchronous. It is a weird thing to get used to.


thanks, though i am confused. I just need the json returned from the api endpoint. now whatever I do I get the promise. how can i get it in a map {}? There surely should be a way to get the value, how else can I operate on a data structure?

Jimmy Miller02:11:43

You call then on it. The function you pass to then will get handed the data. Above instead of printing you could call js->clj to get it into a map. You only gen the value in the then. That is just how these things work. This is just the nature of JavaScript.

Jimmy Miller02:11:39

I’d really recommend taking some time to learn JavaScript and how its asynchronous model works first. It is a big learning curve. But it makes sense after you do it a lot.


I guess I've found the issue: the code above won't print anything, nor the request body, so it appears that it only returns a promise, but does nothing else. The thing is, the print function is never called. The question is why it's not printing, ie calling the callback func? Can it be because of my setup? I am using shadow-cljswith node repl,


I can curl the url alright, with response time of 0.14 ms

Jimmy Miller17:11:01

npx create-cljs-project node-fetch-app
cd node-fetch-app
npm install node-fetch
npx shadow-cljs node-repl
Wait for that to load. Then type the following code:
(require '["node-fetch" :as fetch])

(-> (fetch "")
    (.then (fn [res] (.json res)))
    (.then (fn [json] (println json))))
I just did that and it printed out the response. If it doesn’t for you, there is something wrong with your environment.


alright, thanks a lot for writing this up! I guess it's my setup, i've restarted shadow-cljs server and repls; sometimes it works, sometimes it does not..

Jimmy Miller16:11:28

You can use (.catch (fn [error] (println error))) to see if there is a error being returned


Thank you jimmy, you've been of great help