Node.js server on Azure


It is easy to use Node.js on a CentOS VM running on Azure, or any other linux VM on Azure. You can simply yum (with EPEL) install Node.js. Then an easy way to check if everything is working fine, a good idea is to test running a server from node. I am using this simple snippet:

var http = require('http')

var server = http.createServer(function (req, response){
  response.writeHead(200, {"Content-Type":"text/plain"});
  response.end("Hello World");
});

server.listen(8080);

Now you can start it by typing

node app.js

To access this server that you just started, you need to access this port. This server is listening to port 8080. So you need to enable an endpoint on you Azure VM. Go to Microsoft Azure > yourazurevm > Settings > Endpoints and click add.
Capture
Then set following:
Capture
Endpoint: Any name (e.g. Http 8080)
Protocol: TCP
Public port: 8080
Private port: 8080

Now, hit okay and wait for the VM to enable this endpoint (a.k.a. port).

Capture

After this is enabled, you can now go to http://yourazurevm.cloudapp.net:8080/ and see hello world.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.