Node target for server-side projects


I was wondering has there been any work done on a nodejs/iojs target, so that you could use HaXe/OpenFL as a full-stack development framework? It would be nice to be able to program both the server and client in the same language. Meteor.js is a good example in the javascript world, but with OpenFL you could build the client for multiple platforms, depending on your needs.

You can make a nodejs application in haxe

I remember seeing commits made for support of nodejs in lime/openfl ( and there are some #if nodejs #end
but I don’t know if it’s working.

Thanks! That looks promising and should contain everything to get started. :slight_smile:

I think there is a Node module called “ndll” on NPM, that provides the support. If it works for you, I would be happy to hear feedback. Neko, C++ and other targets could be used on a server as well

You could also try using -Ddisable-cffi, which does not run as quickly, but should avoid CFFI dependencies, this might work in Node without having the NDLL module installed

Most of samples in used to work on io.js, but not now.
But most of problems coming from improper conditional compilation macros so it’s not very hard to fix. We should use #if (js && html5) rather than #if js as “js” is also defined on Node.js target.

To install node-ndll with npm follow this guide.

You’ll be able to run lime samples with this fix, at least on io.js v1.8.1. I created pull request for that.

I built node-ndll with VS2013 on windows and with gcc on Linux. I haven’t tried other compilers yet.
After successfully installing node-ndll, all you have to do is just typing “lime test nodejs” on console.
You could do the same thing on FlashDevelop. You just need to type target name manually.

It would be nice to have setup command like “lime setup nodejs”, which installs VS2013, io.js, node-ndll, and sets NODE_PATH, but we don’t have it yet.

@vroad I just tried to install again, and got further!

Install io.js

I went to and downloaded and ran the Windows 64-bit install. Pretty simple.

Install NDLL Module

npm -g install ndll failed at first. I realized that “node-gyp” was not installed, so I used npm -g install node-gyp. npm -g install ndll still failed, then I saw that node-gyp was not available command in the PATH. I run “C:\Program Files\io.js\nodevars.bat” from within my command-prompt, and then npm -g install ndll worked!

Compile Test Project

I tried to compile a sample project, but it wanted the “nodejs” haxelib to be installed. I used haxelib install nodejs, but it still reported some issues with the Sys and other classes. I went and cloned your copy at (and used haxelib dev to set it as the current version) and got only one remaining error.

I assume you are using Haxe 3.1.3, since I have Haxe 3.2 RC2, there was an additional BytesInput class I needed to override in order to work properly. I just sent a pull request to “nodejs-std” with the added file.

Trying lime test nodejs, I still received an error that it could not find the “ndll” module. I went into “Export\windows\nodejs\bin” and ran npm install ndll to install a local copy for now.

This time it ran! I unfortunately got “Could not load lime.ndll.” messages, though, before throwing an error at var handle = lime_audio_openal_ALC.lime_alc_open_device(deviceName);

The file is right there, I wonder if this is a path thing

I think that official nodejs-std in github has already accepted my pull request for adding Sys stuffs.
Your pull request should be sent to official repo, I guess.
nodejs-std in haxelib doesn’t work? They just haven’t published it to haxelib, maybe.

To load globally installed node modules, you have to set NODE_PATH correctly, as I described in node-ndll’s README.
Also, aren’t you trying to load 32bit NDLLs from 64bit io.js? NDLLs should be built as 64bit if you want to use 64bit io.js. Current lime doesn’t officially support building 64bit lime.ndll on Windows, does it?

If this solution doesn’t work, you may need to debug node-ndll with Visual Studio’s debugger to see what’s happening inside.

Ah, interesting, that might do it. If it was a different architecture, it would not return as finding the binary, so that may just be it.

Do you think that people should install 32-bit io.js, or do you think that we should start doing 64-bit Windows builds?

On Linux, it’s expected to have different 32- and 64-bit versions. Mac is such a closed ecosystem, 32-bit doesn’t exist. I’ve debated Windows 64, but always felt that the simplicity of one Windows build was better than having separate architectures

64bit should be better in performance but not supported on all machines… I think we need to provide with both binaries for better perforamnce and compatibility.
Also, detecting which architecture of Node/io.js is installed is not so easy.

I tried 64bit lime.ndll by myself before (with -D HXCPP_M64) and it seemed working properly on 64bit Node.js.