hey everyone - new at kotlin javascript... trying ...
# javascript
c
hey everyone - new at kotlin javascript... trying to use ktor http client and I am getting this error. I can see in my web directory I have ktor-client-js.js
n
If your'e using IntelliJ can you please output what is shown in External Libraries (inside the Project window).
What JS scripts are registered in HTML for the project, and in what order?
Showing the contents of HTML used by the project would be helpful.
c
image.png
it's a nodejs app - so there isn't html
a
How do you run your application?
c
gradle build && node web/output.js
a
I'm also trying to run ktor http client on nodejs
You should add environment variable `NODE_PATH`:
Copy code
NODE_PATH=web node web/output.js
But then I've got exception:
Copy code
/home/alexk/projects/elastic-driver/web/kotlinx-coroutines-core.js:2687
    throw new DispatchException('Unexpected exception running ' + this, e);
    ^
DispatchException: Unexpected exception running DispatchedContinuation[NodeDispatcher@1, [object Object]]; caused by ReferenceError: window is not defined
    at DispatchedContinuation.DispatchedTask.run (/home/alexk/projects/elastic-driver/web/kotlinx-coroutines-core.js:2687:11)
    at Timeout._onTimeout (/home/alexk/projects/elastic-driver/web/kotlinx-coroutines-core.js:19743:17)
    at listOnTimeout (timers.js:324:15)
    at processTimers (timers.js:268:5)
c
ha thought I tried that before!
have the same error as you now
are you using my gradle file?
a
No, I have my own test project that I curious to run on nodejs
n
Have you tried using Ktor Client (JS ver) via Gradle instead of Node?
c
is there a node version?
n
Noticed in the External Libraries list that Ktor Client (JS ver) has been copied, yet some other Kotlin JS libs are being included via Gradle.
What is the output from the source sets in the Gradle window. Are there any red squiggles?
c
image.png
n
Be sure to try out using Ktor Client (JS ver) without Node (just use Gradle), and see if the program runs fine. Presumably Ktor Client (JS ver) doesn't require Node?
c
it will probably run because window is something that comes from a web browser...
here is most of my code
it looks as though node should be supported
n
Presumably you are trying to do some UI testing using a major Web Browser?
c
no I want to make a node js web server using express js and use ktor http client to call restful APIs
btw it gets futher in a web browser but is stopped by cors - added a comment to my github gist
🆗 1
I managed to write an engine for the
HttpClient
that uses https://nodejs.org/api/http.html
c
Nice have you created a pull request?
a
Need some time to finish. I'm not familiar with javascript and node. And for PR there also should be some tests.
c
Let me know if you would like a hand or code review. Try copy the existing tests