2

I want to run my nodejs project on IIS.

I got this message:

iisnode encountered an error when processing the request.

HRESULT: 0x2
HTTP status: 500
HTTP subStatus: 1002
HTTP reason: Internal Server Error

You are receiving this HTTP 200 response because system.webServer/iisnode/@devErrorsEnabled configuration setting is 'true'.

In addition to the log of stdout and stderr of the node.exe process, consider using debugging and ETW traces to further diagnose the problem.

The last 64k of the output generated by the node.exe process to stderr is shown below:

Application has thrown an uncaught exception and is terminated:
C:\Program Files\iisnode\www\helloworld\server.js:2
import express from 'express';
       ^^^^^^^

SyntaxError: Unexpected identifier
    at new Script (vm.js:79:7)
    at createScript (vm.js:251:10)
    at Object.runInThisContext (vm.js:303:10)
    at Module._compile (internal/modules/cjs/loader.js:657:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)

my code is on this path:

C:Program Files/iisnode/www/helloworld

I'm running on port 86:

localhost:86

this is my web.config inside helloworld/web.config:

<configuration>
  <system.webServer>

    <!-- indicates that the hello.js file is a node.js application 
    to be handled by the iisnode module -->

    <handlers>
      <add name="iisnode" path="server.js" verb="*" modules="iisnode" />
    </handlers>

    <!-- use URL rewriting to redirect the entire branch of the URL namespace
    to hello.js node.js application; for example, the following URLs will 
    all be handled by hello.js:

        http://localhost/node/express/myapp/foo
        http://localhost/node/express/myapp/bar

    -->
<security>
      <requestFiltering>
        <hiddenSegments>
          <remove segment="bin"/>
          <add segment="node_modules"/>
        </hiddenSegments>
      </requestFiltering>
    </security>
    <rewrite>
    <rules>
      <rule name="LogFile" patternSyntax="ECMAScript" stopProcessing="true">
                     <match url="^[a-zA-Z0-9_\-]+\.js\.logs\/\d+\.txt$"/>
                </rule>

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

        <rule name="NodeLog">
          <action type="Rewrite" url="iisnode{REQUEST_URI}"/>
        </rule>

        <!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
        <rule name="StaticContent">
          <action type="Rewrite" url="public{REQUEST_URI}"/>
        </rule>

        <!-- All other URLs are mapped to the node.js site entry point -->
        <rule name="DynamicContent">
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
          </conditions>
          <action type="Rewrite" url="server.js"/>
        </rule>
      </rules>

    </rewrite>
    <httpErrors existingResponse="PassThrough" />
     <iisnode watchedFiles="web.config;*.js;node_modules\*;client\*"/>
  </system.webServer>
</configuration>
S.M_Emamian
  • 17,005
  • 37
  • 135
  • 254
  • With nodejs you can create a web server, why do you need IIS then? – Oscar Calderon Jan 09 '19 at 13:01
  • 1
    my server is a windows OS. – S.M_Emamian Jan 09 '19 at 13:02
  • NodeJS runs on Windows or Linux by itself, without needing another server – Oscar Calderon Jan 09 '19 at 13:03
  • 1
    I have a website on a windows OS. http://example.com. now I want to run my nodejs on a sub domain of it. like this: http://node.example.com. Can I do this without iis? – S.M_Emamian Jan 09 '19 at 13:06
  • 1
    Depending of how much control of your windows box you have, simply execute node in another port different than iis, and point your subdomain to that url and port. – Oscar Calderon Jan 09 '19 at 13:09
  • Possible duplicate of [Node.js - SyntaxError: Unexpected token import](https://stackoverflow.com/questions/39436322/node-js-syntaxerror-unexpected-token-import) – ponury-kostek Jan 09 '19 at 13:17
  • IIS is a webserver, Node is another webserver. They are competitors. It's like asking, "How can I run my Samsung phone from my iphone?" it doesn't make any sense. – Jeremy Thille Jan 09 '19 at 13:47
  • As far as I know, if you are running your nodejs app locally in your Windows Server and you want it to be able to accessed from normal url from the web, you need to use the URL Rewrite module in IIS to create a inbound rule and rewrite the url to your local nodejs app (http:localhost:3000). I have successfully done a few projects with this pattern and it is working fine. Let me know if you want to know more about the details. – jet_choong Nov 12 '19 at 03:21

0 Answers0