Hosting node.js on Windows Azure worker role

Source: Internet
Author: User
Keywords Azure node.js azure

In my previous article I demonstrated how to http://www.aliyun.com/zixun/aggregation/32995.html "> Develop and deploy Node.js applications on Windows Azure Web site (that is, waws)." Waws is a new feature in the Windows Azure platform. Because it is low-cost, it provides both IIS and
Iisnode components, so we can host node.js applications via Git, FTP, and WebMatrix without any configuration and component installation.

But sometimes we need to use Windows Azure cloud computing Services (i.e. WACS) while hosting our node.js on the worker role. Here are some benefits of using the worker role.

-waws uses IIS and Iisnode hosted Node.js applications to run in x86 wow mode. It reduces performance comparisons with x64 in some cases.

The-wacs worker role does not require IIS, so there are no IIS restrictions, such as 8000 concurrent request restrictions.

-WACS provides developers with more flexibility and control. For example, we can RDP to the virtual machine of our worker role instance.

-The service configuration features provided by WACs can be changed when the role is run.

-wacs offers more scalability than waws. In Waws, we can have up to 3 reserved instances per site, although in WACs we can book up to 20 instances at a time.

-So when using the WACs worker role, we start the node in the process ourselves, we can control the input, output, and error stream. We can also control the Node.js version.

Running Node.js in worker roles

Node.js can be started by owning its executable file. This means that in Windows Azure we can have a worker role with the source files for "Node.exe" and Node.js, and then start in the secondary role entry class method.

Let's create a new Windows Azure project in Visual Studio and add a new worker role. Since we need our worker roles and application code to perform "Node.exe", we need to add "Node.exe" to our project. Right-click the Worker role project to add an existing item. By default node.js will be installed in the program Files\nodejs folder, so we need to navigate there and add "Node.exe".

Then we need to create the Node.js entry code. The portal file must be named "Server.js" in Waws because it is hosted by IIS and Iisnode, and Iisnode only accepts "Server.js". But here as we control everything we can select any file as input code. For example, creating a new JavaScript file in the root project is named "Index.js".

--Since we created a C # Windows Azure project, we cannot create a JavaScript file from the context menu "Add New Item". We have to create a text file and rename it to
JavaScript extensions.

After we add these two files, we should set the copy to output directory property to "always copy" or "Copy if it is newer." Otherwise they will not involve packages at deployment time.

Paste the very simple node.js code in "Index.js" as shown below. As you see, I created the Web server listening on port 12345.

1:var http = require ("http");

2:var port = 12345;

3:

4:http.createserver (function (req, res) {

5:res.writehead ({"Content-type": "filetype")
});

6:res.end ("Hello world\n");

7:}). Listen (port);

8:

9:console.log ("Server running at Port%d", port);

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.