none
[Node.js][Web Apps] can't set --use_strict globally on Microsoft Azure RRS feed

  • Question

  • I have hosted my nodejs (with es6) application Microsoft Azure, it always returning internal server error (500).

    See, I have a package.json which is the actual entry point of my app as I have written following code in it to run the app in strict mode from /bin/www

    "scripts": {
        "start": "node --use-strict ./bin/www"
      },

     

    I read http://tstrimple.com/express-4-azure-websites/ and found that I had to change the path `app.js` to `/bin/www` in three places in web.config file. I have tried it but I still couldn't run the app in strict mode. The only one solution is to add "use strict" in all files which I don't like actually. Please suggest the solution which you provided to run the whole app in strict mode.




    Tuesday, May 31, 2016 2:38 PM

Answers

  • You can try to create a iisnode configuration file named `iisnode.yml`in the root directory of your application with the following content:

    nodeProcessCommandLine: "D:\Program Files (x86)\nodejs[\version]\node.exe" --use-strict

    E.G.

    nodeProcessCommandLine: "D:\Program Files (x86)\nodejs\6.0.0\node.exe" --use-strict


    Wednesday, June 1, 2016 5:27 AM
    Moderator

All replies

  • You can try to create a iisnode configuration file named `iisnode.yml`in the root directory of your application with the following content:

    nodeProcessCommandLine: "D:\Program Files (x86)\nodejs[\version]\node.exe" --use-strict

    E.G.

    nodeProcessCommandLine: "D:\Program Files (x86)\nodejs\6.0.0\node.exe" --use-strict


    Wednesday, June 1, 2016 5:27 AM
    Moderator
  • Thank you! It is added and hope it will work.

    I have another additional question which is regarding the same. As I mentioned in the initial question I have edited web.config by replacing `app.js` with `bin\www` to start-up script from `bin\www` but I still see(from the deployment details)

    remote: Copying file: 'iisnode.yml'
    remote: Start script "--use-strict ./bin/www" from package.json is not found.
    remote: Looking for app.js/server.js under site root.
    remote: Using start-up script app.js
    remote: Generated web.config.
    remote: The iisnode.yml file explicitly sets nodeProcessCommandLine. Automatic n
    ode.js version selection is turned off.

    But it should start-up script `bin\www` as per my configuration, see my web.config changes below

        <handlers>
            <!-- Indicates that the server.js file is a node.js site to be handled by the iisnode module -->
            <add name="iisnode" path="/bin/www" verb="*" modules="iisnode"/>
        </handlers>

        <!-- Do not interfere with requests for node-inspector debugging -->
        <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
              <match url="^bin\/www\/debug[\/]?" />
         </rule>

         <rule name="DynamicContent">
              <conditions>
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
              </conditions>
              <action type="Rewrite" url="/bin/www"/>
          </rule>

       Remove segment is also there in web.config, so it should off course load from bin\www

        <!-- 'bin' directory has no special meaning in node.js and apps can be placed in it -->
        <security>
          <requestFiltering>
            <hiddenSegments>
              <remove segment="bin"/>
            </hiddenSegments>
          </requestFiltering>
        </security>

    Please help.

    Wednesday, June 1, 2016 7:37 AM
  • Have you changed back the npm start script to 

    "scripts": {
        "start": "node ./bin/www"
      },

    As during the deployment task, it will depend the start script and search the entrance script in your application.

    Your original script "node --use-strict ./bin/www" maybe is not is the correct format that the task cannot find the file.

    Wednesday, June 1, 2016 8:00 AM
    Moderator
  • Thank you!, it works.

     I have updated iisnode.yml as you suggested to enable --use_strict globally, following are the code(my node js version is 4.2.3).

     nodeProcessCommandLine: "D:\Program Files (x86)\nodejs\4.2.3\node.exe" --use-strict

    But I still get the same error "Block-scoped declarations (let, const, function, class) not yet supported outside strict mode".

    There is an update happens which I can see in the deployment details. 

    remote: Updating iisnode.yml at D:\home\site\wwwroot\bin\iisnode.yml
    remote: Finished successfully.
    remote: Running post deployment command(s)...
    remote: Deployment successful.

    I checked the new file D:\home\site\wwwroot\bin\iisnode.yml via FTP, --use-strict is not there in the file. it contain the following line of code 
    nodeProcessCommandLine: "D:\Program Files (x86)\nodejs\4.2.3\node.exe"

    Please let me know if anything went wrong.

    Wednesday, June 1, 2016 10:36 AM
  • You need to make sure that iisnode.yml is part of the files that you deploy. If you don't deploy one, it will get created at deployment time and override the one you manually edited. That is expected behavior.

    See also this question.

    David

    Wednesday, June 1, 2016 1:33 PM
  • Yes, iisnode.yml is the part of my deployment. But what was happening is the server copied iisnode.yml file to bin for in my last deployment and that copied file contains the path to node.exe (nodeProcessCommandLine: "D:\Program Files (x86)\nodejs\4.2.3\node.exe") not `--use_strict`.

     I think I have to keep iisnode.yml in `bin` folder as we set the start point to `bin\www`. Please confirm.

    Wednesday, June 1, 2016 2:00 PM
  • I would have expected it to always be at the root of your site, i.e. in d:\home\site\wwwroot, but I may be wrong.

    It should be easy to see which one is actually being used at runtime by using Kudu Console to edit it at the various level and check which one is taking effect.

    You can also use Kudu process explorer to look at the node.exe process properties and confirm that the command line has the extra switch.


    • Edited by David Ebbo Thursday, June 2, 2016 5:13 AM typo
    Wednesday, June 1, 2016 2:06 PM
  • Okay, thank you very much for your great support!
    Thursday, June 2, 2016 5:08 AM