Sunday, May 20, 2012

Hello Vertx Javascript

Everyone is talking about node.js but another new kid in town is vert.x which is similar in nature to node (talking in terms of javascript server side programming). So today we will write Hello World in vertx.   


Steps :: 

  • Click here to download vertx or go to vertx home page here
  • Create environment variable VERTX_HOME with value as extracted vertx directory
  • Add %VERTX_HOME%\bin to %PATH%

Now you are ready to code.
Here is the code

load('vertx.js')


//Configure Vertx server to listen on port 8080 for incoming http requests
vertx.createHttpServer().requestHandler(function(req) {
  req.response.end("<html><body><h1>Hello from vert.x!</h1></body></html>");
}).listen(8080, 'localhost');

stdout.println("Server is running on " + "http://127.0.0.1:8080");


Save above code as server-helloworld.js


Start node server as
>vertx  run server-helloworld.js
Server is running on http://127.0.0.1:8080
Now go to http://127.0.0.1:8080/ and see the magic

Lots of valuable tutorial for various vertx utilities are located in %VERTX_HOME%\examples\javascript

For above code check in %VERTX_HOME%\examples\javascript\http directory.

1 comment:

  1. The only thing to watch out for is to ensure you don't pass the result of a previous promise onto a subsequent promise that is unrelated. psd to email

    ReplyDelete