How to run Node JS Application With IIS
Rashid Bilgrami
IT Manager & Business Automation Expert (SharePoint) - PMP Certified & Kaizen Certified From Japan
If you want to configure the Node.js application with IIS, this article will likely solve your issue.
Let's begin:
If you have the IIS8 or + version URLREWRITE will have already been installed but for the safe side, you can download it and install it again.
2. Add the website to the IIS
Make sure, you IIS website port must be similar to the port used in the code.
[Your Code].....}).listen(3000);
3. Check your new website modules to ensure iisnode is installed
Following lines of code, you can add to your web.config file under the project folder. My project is under the D:\Rashid\Studeies\Node JS\School Students folder, so the web.config file is present under the following folder.
<configuration>
<system.webServer>
<handlers>
<add name="iisnode" path="node_app.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<rule name="nodejs">
<match url="(.*)" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="/node_app.js" />
</rule>
</rules>
</rewrite>
<security>
<requestFiltering>
<hiddenSegments>
<add segment="node_modules" />
<add segment="iisnode" />
</hiddenSegments>
</requestFiltering>
</security>
</system.webServer>
</configuration>
领英推荐
Make sure the IIS user has full permission on the project folder and node.js folder. The location of Node.js folder is under C:\Program Files\nodejs or the folder where you installed node application.
Once you run the application on the browser, the Following error will through
HRESULT: 0x
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:
Error: Cannot find module 'express'
Require stack:
- D:\Rashid\Studeies\Node JS\School Students\node_app.js
- C:\Program Files\iisnode\interceptor.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
at Function.Module._load (internal/modules/cjs/loader.js:746:27)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:101:18)
at Object.<anonymous> (D:\Rashid\Studeies\Node JS\School Students\node_app.js:1:15)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Module.require (internal/modules/cjs/loader.js:974:19)2
To resolve the above problem you need to open the command prompt and point to the project directory. Make sure your directory must be same as the project directory. As I mentioned My project is in D:\Rashid\Studeies\Node JS\School Students so I accessed my project directory
Install the express by running the following command
npm install express --save
After that refresh, your page and boom your node site will work perfectly on IIS.
I hope, this article will save your time a lot
Regards
Rashid Imran Bilgrami
IT Manager & System Automation Expert
Saudi Japanse Automobile High Institute
Contact: [email protected]
4 个月Thanks for the guidance