none
[Node.js][Web Apps] Deploying Node App Via Windows Azure RRS feed

  • Question

  • Hello,

    I have a Node.js web site. I am able to run this site locally by running node ./src/server.js from the command-line. My repository is structured like:

    src
        routes
        views
        server.js
    .deployment
    .gitignore
    README.md
    gulpfile.js
    package.json

    The .deployment file contains the following:

    [config]
    project = src

    When I visit the Azure site, I get a 500 error. When I view the logging-errors.txt file in Kudo, I see the following:

    Unaught exception: SyntaxError: Unexpected reserved word
        at Module._compile (module.js:439:25)
        at Object.Module._extensions..js (module.js:474:10)
        at Module.load (module.js:356:32)
        at Function.Module._load (module.js:312:12)
        at Module.require (module.js:364:17)
        at require (module.js:380:17)
        at Object.<anonymous> (D:\home\site\wwwroot\routes\about.js:4:11)
        at Module._compile (module.js:456:26)
        at Object.Module._extensions..js (module.js:474:10)
        at Module.load (module.js:356:32)

    I do not understand why I would be getting this error in Azure when everything runs fine locally. My package.json file looks like this:

    {
      "name":"Website",
      "version":"1.0.0",
      "private": true,
      "scripts": {
        "start": "node ./src/server.js"
      },
      "description": "My Website",
      "devDependencies": {
        "bower":"^1.5.2",
        "del":"^1.1.1",
        "gulp":"^3.8.11",
        "gulp-concat":"2.6.0",
        "gulp-exec":"^2.1.1",
        "gulp-jasmine":"^2.0.1",
        "gulp-jshint":"~1.11.2",
        "gulp-livereload":"^3.8.1",
        "jasmine":"^2.3.2",
        "jasmine-terminal-reporter":"^1.0.0",
        "run-sequence":"^1.1.1",
        "yargs":"^3.15.0"
      },
    
      "dependencies": {
        "body-parser":"~1.8.1",
        "cookie-parser":"~1.3.3",
        "debug":"~2.0.0",
        "express":"~4.9.0",
        "morgan":"~1.3.0",
        "serve-favicon":"~2.1.3",
        "swig":"1.4.2",
        "xml2js":"^0.4.12"
      },
    
      "engines": {
        "node":"4.0.0"
      }
    }

    Why doesn't this run in Azure?




    Monday, January 18, 2016 10:07 PM

Answers

  • As Node.js applications running on Azure are hosted on IIS via IISnode, you need to configure URL rewrite mode and requests handler mappings to your application in the configuration file named "web.config" in your root directory.

    Here is a sample.

    The project directory is for example:

    bin/
        |server.js
    node_modules/
    public/
    views/
    routes/
    ...
    package.json
    Web.config

    Run "node bin/server.js" to start the application on local.

    And the content of Web.config is:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <system.webServer>
        <staticContent>
          <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
        </staticContent>
        <modules runAllManagedModulesForAllRequests="false" />
    
        <iisnode watchedFiles="web.config;*.js;routes\*.js;views\*.jade"/>
    
        <handlers>
          <add name="iisnode" path="/bin/server.js" verb="*" modules="iisnode" />
        </handlers>
    
        <security>
          <requestFiltering>
            <hiddenSegments>
              <remove segment="bin" />
            </hiddenSegments>
          </requestFiltering>
        </security>
    
        <rewrite>
          <rules>
            <clear />
            <rule name="app" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
              <match url="iisnode.+" negate="true" />
              <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
              <action type="Rewrite" url="bin\server.js" />
            </rule>
          </rules>
        </rewrite>
      </system.webServer>
    </configuration>

    Tuesday, January 19, 2016 1:52 AM
    Moderator