I’m trying to set up a NodeJS backend for use with my Haxe client JS application. Unfortunately, I can’t find any working example. The official haxe nodejs library has seen quite little action lately. I’ve tried using an example from here:
But it doesn’t compile with my IntelliJ IDEA Haxe plugin. The following imports cannot be found:
The first directory for hxnodejs is right. It should be pointing to the version path. The Haxe plugin will look at the haxelib.json to find the proper source roots.
However, the js-kit entries should be in another library – because only one haxelib.json is expected for each library, so none of those sources will be found.
You also have to add the library dependencies to the module you are building.
@ebishton done & done :). Still acting up. I’m getting code completion for js.Node.http. It capitalizes Node but when autocompleting “Http” to finalize the import it makes it to “node”. It can’t find either. When I investigate “External Libraries” via IntelliJ Project Explorer I can see these packages. But neither code completion NOR compilation works.
I used haxe 3.4.7 and hxnodejs from NPM.
I fixed your class like that :
package ;
import js.Node;
import js.node.Http;
/**
Example web server from the node.js main page
**/
class WebServer {
static function main() {
Http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
Node.console.log('Server running at http://127.0.0.1:1337/');
}
}
@damoebius It worked :). Actually I think @ebishton’s answer is also good. It’s my bad that I didn’t actually point to the sources folder!
@damoebius Oh, you made a game with Haxe, nice! :). Did you find that hxnodejs is sufficiently up to date to use the latest features of Node? How do you work with Node when you recompile often? Use something like nodemon?
@damoebius Thank you! :). One more question, on topic: how do you debug?
From what I understand you linked some of your node externs? But they’re not specifically for node itself, but for libraries that you use with node, or am I missing something?
@damoebius Things are starting to work, thanks to you :). I’m a bit of a noob when it comes to Node however. I see you use express. I’m looking at your code trying to determine how I can make Node respond differently to a different URL request, but I’m stuck at the step of adding Express to my project.
How did you add this to your project? I assume I install express using NPM and use your Haxe externs class, but I assume I have to add express sources somehow to my project.
A-ha! It was your “hxexpress” mention I was needing . I don’t use NPM to build my project. I just use IntelliJ and haxelib to get required packages. That seems to be enough.
In the meantime I noticed that Chrome developer tools keeps getting disconnected every time nodemon restarts the server. Then I have to copy paste the new URL into Chrome which is somewhat of a chore .
Also, I don’t see my HX files . I only see the compiled JS. Chrome says it detects the source map, but unfortunately nothing is there, unlike my client application which works fine (Chrome shows HX files and I can debug them).
Thank you for dedicating a bit of your time for all this. Haxe is a small community compared to others and not that many people to help out. I think I’m going to be more active around here too :).
I’m barely starting with a story-based game (interactive story). Haxe is really refreshing as a language . I feel like on an adventure, which goes perfectly hand in hand with the open world interactive story I’m building
@damoebius I’m cloning your game now, looking into learning some stuff from there. It’s an interesting project I think. I like the concept of training AIs :). I’m actually also into some AI stuff for a possible project. Would you be interested in connecting outside this Forum a bit? If so, can you share a contact method?