Node.js example

Here you will see an original node.js code and the Haxe version of the same code. I will not do that every time, so this is just an example to show you that there is not a lot of difference between the two ways.


// example.js

var http = require('http');
var server = http.createServer(
      function (req, res) {
        res.writeHead(200, {'Content-Type': 'text/plain'});
            res.end('Hello World\\n');

server.listen(1337, "");
console.log('Server running at');


In terminal:

node example.js
# Server running at

Haxe example

haxe node

// Haxenode.hx

package ;

import js.Node;
import js.node.Http;
import js.node.http.ServerResponse;
import js.node.http.IncomingMessage;

class Haxenode
    static public function main()
        var server = Http.createServer(function (request:IncomingMessage, response:ServerResponse):Void
            response.end('Hello World\\n');

        trace( 'Server running at' );

Compile & run

In terminal:

haxe -lib hxnodejs -js haxenode.js -main Haxenode
node haxenode.js
# Server running at

results matching ""

    No results matching ""