Getting started with Node.js

On August 9, 2012, in How-to, Technical, by Raymond

Ray PenalosaNode.js is a new interpreter that allows JavaScript to be processed on the server side.  It is installed and enabled (as a beta service) on the DiscountASP.NET web servers.  To gain the full use of node.js, all you need to do is setup the Handler Mapping to route all .js file extensions to the Node.js interpreter.  This has to be done within the applications web.config file.

There are two ways to do this.  The easiest way is through IIS 7 Manager.  You can use this Knowledge Base article for details on how to connect to our web server with IIS 7 Manager.

Once connected, go to the “Handler Mapping” module.  Click on “Add Module Mapping.

Enter the settings as you see them.  Now you have your application set to push all *.js files to Node.js.

You do not have to use IIS 7 Manager to create this mapping.  You can directly code it within your application’s web.config file.  What you will need to look for is the ‘system.webserver’ element within the configuration of the web.config file and add the handler line:

<configuration>
  <system.webServer>
    <handlers>
    <add name="iisnode" path="*.js" verb="*" modules="iisnode" />
    </handlers>
  </system.webServer>
</configuration>

One of the things you will need to be aware of is that all *.js files will be processed by the node.js engine.  The side effect of that is some of the JavaScript on your pages may not function correctly because they are no longer being sent to the client’s browser for processing.  I tested an HTML5 page which uses a lot of JavaScript and some of the features in the HTML5 page did not work.

There are a couple of work-arounds to this:

1. Upload the .js file you want to be processed by node.js to its own subfolder.  Then add the web.config setting to that folder.

2. You can specify which .js file gets processed by the node.js engine.  In the path field, rather than implementing a wild card, you can set: path=”somefile.js”.

 

10 Responses to “Getting started with Node.js”

  1. Hamid Abdulmalik says:

    Thanks for the time you took to explain how to host node.js apps on discountasp.net. I followed the same steps but it did not work with me. Is it possible that you may have missed something or is node.js support temporarily down for some reasons. Thank you.

  2. Raymond says:

    What exactly is the problem? The steps I oultined has been tested and node.js is already installed on the server. There’s really nothing else we need to enable for node.js to work other than what I outlined and of course coding correctly for it. Have you tried posting your problem on our forum? forum.discountasp.net
    We may have a member who ran into the same problem you did and come up with a solution.

    • Hamid Abdulmalik says:

      Thanx for your responce. My problem is as follows:
      1) My server failed the WebMatrix Publish compatibility test for Node.js, despite the fact that it passed when I ran the same test agains your sandbox edition of Node.js.

      2) In search of results, I came across your outlined solution above, but it did not run given the fact that the failed compatibility test clearly states Node.js is not available.

      What I am suggesting is if you could somehow check your servers again to make sure all grounds are coverd. thank you.

  3. Jason says:

    I still cant find any decent guides on deploying node.js to my DiscountASP site. If Im not mistaken if you use web matrix to create a node js site it already takes care of

    • Raymond says:

      Deploying node.js is as simple as using FTP and uploading it to the web server. If you need some kind of tool to help you create node.js base websites, then yes Web Matrix can help you. The new Web Matrix has several Node.js base templates you can use.

  4. […] What it means to be a .NET developer is evolving.  So we are constantly evolving our hosting platform. We launched support for node.js on our Windows 2008 and Windows 2012 hosting platforms. Raymond posted on getting started with node.js. […]

  5. Alex Banks says:

    I do not want all my my JS processed on the server. I am simply tring to get a sample Chat Web Socket example to work on DiscountASP.NET

    So I have a single file that is the code for the web socket. How do I go about getting it to work with ws://MYDOMAIN??

    Is there a place to run NODE JS commands? Do I have to set these up in the web config?

    • Raymond says:

      In the add module mapping you can specify which file will be processed by node.js. In the line..

      Set it to

      • Alex Banks says:

        Set it to what? I am hanging on your every last word!

        • Raymond says:

          Did you read the entire blog? At the bottom of the blog it shows you how to specify a specific file to be processed by Node.js. That means all other .js files will be processed normally.

          ———————–
          One of the things you will need to be aware of is that all *.js files will be processed by the node.js engine. The side effect of that is some of the JavaScript on your pages may not function correctly because they are no longer being sent to the client’s browser for processing. I tested an HTML5 page which uses a lot of JavaScript and some of the features in the HTML5 page did not work.

          There are a couple of work-arounds to this:

          1. Upload the .js file you want to be processed by node.js to its own subfolder. Then add the web.config setting to that folder.

          2. You can specify which .js file gets processed by the node.js engine. In the path field, rather than implementing a wild card, you can set: path=”somefile.js”.

Leave a Reply

iBlog by PageLines