How to run Node.JS server for a web application? - node.js

Info: I am very new to node.JS!
I have written a sample server that can listen to http requests on port XXXX. When I run this server from commandline (Windows) it seems to work well. It responds to the requests made to localhost:XXXX when opened in a browser.
Question: Is this how this is supposed to work? For the node server to run, should there always be a CMD prompt open for the server to listen to requests?
Can I not do "something" with IISNode?
I understand that if I make a request to a JS files, which is noted in IISNode as a Node.JS file and that NODE should be handling it; then I will have Node handling the request for me.
But then this assumes that IIS is the web server for me and that specific requests can be handled by Node.
I hope I am making sense here! :)

On Windows you have two options of hosting node.js applications:
Self-host the node.exe process just like you would on *nix. During development you will probably just start it from the command line. In production you want to come up with a mechanism that will provide process lifetime management around node.exe (e.g. start it when the OS starts). The most reasonable way of doing it on Windows is to use Windows Services (also known as NT Services). A component that can help you do this is http://nssm.cc/.
Host node.js with the IIS using iisnode (http://github.com/tjanczuk/iisnode). Compared to self-hosting this method has a number of benefits outlined in https://github.com/tjanczuk/iisnode/wiki. But you also want to explore the performance implications (not all of them bad actually): http://tomasz.janczuk.org/2012/06/performance-of-hosting-nodejs.html.

I solved it using a proper method. Yes, IISNode it is.. But none of comments seemed to answer how to "run" app.js for different applications hosted on same IIS (which is also serving PHP, ASPX, etc)
Step 1.
Edit your node application’s entry-point (typically) app.js for the new URL structure.
An express app assumes that it owns the entire URL space and starts the URLs from the root itself, as shown:
Edit you app.js to look like the following (but put YOUR app’s directory name instead of “aaspass”!!):
Now put a web.config file at the root of your app which looks like the following (You may use this template: webconfig).
Again edit the file and change the name “aaspass” to your app’s directory name.
Thats it! You may do this for as many apps as required and host them on SAME server.

What worked for me:
Install IISNode
Install URL Rewrite module of IIS
Add web.config file in your Node.js app/folder. Here are the content of web.config file:
In the handler, I just need to point to app.js (typical entry point of your application). I have not made changed to any of my routes (there is no need to append any text).
..
<configuration>
<appSettings>
<add key="NODE_ENV" value="production" />
</appSettings>
<system.webServer>
<handlers>
<add name="iisnode" path="server/app.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<clear />
<rule name="cdw">
<match url="/*" />
<action type="Rewrite" url="server/app.js" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

If you are on Windows you can (and probably should) run Node.js under IIS:
http://www.hanselman.com/blog/InstallingAndRunningNodejsApplicationsWithinIISOnWindowsAreYouMad.aspx

Related

python flask test site not working on IIS server, however it works on localhost

I have been given access to an IIS server
Windows 2012 R2
IIS version 8.5.9600
I successfully installed
python 3.8
wfastcgi
flask
i wrote a basic "hello world" python flask app which i tested and works on the localhost machine
I created my web.config file and has the following
<configuration>
<system.webServer>
<handlers>
<add name="Python FastCGI"
path="*"
verb="*"
modules="FastCgiModule"
scriptProcessor="C:\Python36\python.exe|C:\Python38\Lib\site-packages\wfastcgi.py"
resourceType="Unspecified"
requireAccess="Script" />
</handlers>
</system.webServer>
<appSettings>
<!-- Required settings -->
<add key="WSGI_HANDLER" value="hello.app" />
<add key="PYTHONPATH" value="C:\inetpub\wwwroot\test_site" />
</appSettings>
</configuration>
For this site i enabled IISUsers to have Modify and Write access
I am unable to load the site though. Am i missing anything in the configuration?
When i click on IIS, FasCTI Settings appears and properly points to the python.
I am getting a 500 error in the logs.
help is alwasy appreciated.
Best
DamnGroundHog
So it looks like i have everything correct but i decided to play around with some settings, specifically bindings.
when i changed the port from 80 to 8080 and took the host name away, it worked. Yay! Now i will look at bindings and see why my basic index.html worked but the hello.py didn't
Through my restoration of a project similar to your python project, it can be successfully run on the window server. I follow this tutorial, you can refer to it.
Detail steps
In the process of my application, it only works when the port is also 8080 because the application is deployed under the default website. At the same time index.html works because the default document is set, you can check your default document module.

Error in Node.js with Azure web app service

I am new to Node.js and I have created a basic application in node.js and trying to deploy on Azure web App service.
After successful deployment, when I am trying to hit a website it showing me two types of error like You do not have permission to view this directory or page.
or website not responding.
In both cases, when I tried to trace the logs, it shows me following logs in the things you can try
If you do not want to enable directory browsing, ensure that a default document is configured and that the file exists.
Enable directory browsing using IIS Manager.
Open IIS Manager.
In the Features view, double-click Directory Browsing.
On the Directory Browsing page, in the Actions pane, click Enable.
Verify that the configuration/system.webServer/directoryBrowse#enabled attribute is set to true in the site or application configuration file.
How can I resolve the error?
You can try this approach:-
Create a web.config file at the root of the app directory.
Add the following code to web.config:
<configuration>
<system.webServer>
<!-- indicates that the index.js file is a node.js application
to be handled by the iisnode module -->
<handlers>
<add name="iisnode" path="index.js" verb="*" modules="iisnode" />
</handlers>
<!-- adds index.js to the default document list to allow
URLs that only specify the application root location,
e.g. http://mysite.antarescloud.com/ -->
<defaultDocument enabled="true">
<files>
<add value="index.js" />
</files>
</defaultDocument>
</system.webServer>
</configuration>
Hope it helps. You can try enabling customerror=off to for troubleshooting exact error.For reference please follow:
Azure website message "You do not have permission to view this directory or page.". What to do?
MV

Core 2.0 Publish IIS HTTP Error 500.19 - Internal Server Error

I have read a lot of post with the same error I have. The problem I have is that I have it running on the same machine I developed the solution.
I have Windows 8.1 and IIS 7.5. Express I am running several MVC Framework XXX solutions on me IIS and I do not have problems. The problems appears when I publish a solution Core 2.0...
I have created a basic Web Core 2.0 MVC solution. Just the same project it is created by Default. (Created an Core 2.0 MVC and Publish it).
I have Visual Studio 2017, so I have installed SDK installed.
I have created a site in IIS (inetpub/wwwroot) for it, drop in the published code, and configure the App Pool to run "No Managed Code". I set port to 5010.
When I run the Project from cmd: dotnet core20.dll it says it is running listening on port 5000, instead on port 5010.
So, i set port 5000, but when i run it from cmd it shows an error.
Microsft.AspNetCore.Server.Kestrel[0] Unable to bind to localhost:5000 on the IPv4 loopback interface: Error 4092 EACCES permission denied. Unabled to start Kestrel.
Why it runs on port 5000 if I set on port 5010?
When I run it from Browser i have this error
My web.Config is the basic web.config created ruting the publishing..
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\core20.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>
<!--ProjectGuid: 21dc60b6-a958-447d-8ed3-25a6195a06ea-->
On Windows Features turn on or off--> IIS Services--> Application Development Features, all options are selected
The error I have
I have the same problem with Core 2.0 Angular Application... So I miss to install something.
I have not installed the .NET Core Windows Server Hosting bundle. I do not know it is necessary.
I do not know if i have to install Kestrel, or how to install it.
I asume all this has to be installed when I installed Visual Studio 2017.
Any ideas what I am missing?
thanks
I have not installed the .NET Core Windows Server Hosting bundle. I do not know it is necessary.
There's your problem. Install the hosting bundle. Without it, IIS has no idea how to handle an ASP.NET Core app. In particular, your error here is because the <aspNetCore> tag doesn't exist for usage by Web.config, without that bundle either. So, while the error is a bit obtuse, it is technically telling you what the issue is.
Additionally, after installing the bundle, you must either restart your server or completely stop and restart the IIS service (not iisreset):
> net stop was /y
> net start w3svc
It's better to restart the server entirely, if you can, just to make sure everything is fresh, but starting and stopping web services should be enough to load in the ASP.NET Core module.
All of this is covered in the documentation.

ASP.NET Core 1.1 works under Default website in IIS but not under a custom website

Machine: Windows Server 2012 R2 with IIS 8.5 on a company network.
Following this tutorial
Success: In IIS, deployed a published folder of an ASP.NET MVC Core 1.1.1 app to an Application Folder under Default Website. From a desktop on the same network, browsed to the URL http://IP Address/MyPublishedFolder. The app successfully displayed its home page.
Failure: Created a custom website on the same IIS with one of the DNS Names at the company: Ourapps.ac.CompanyName.com with host folder named as Ourapps.ac.CompanyName.com. Copied the exact same published folder MyPublishedFolder to Ourapps.ac.CompanyName.com. From a desktop on the same network, browsed to the URL: http://Ourapps.ac.CompanyName.com/MyPublishedFolder. Got the browser error: HTTP Error 502.5 - Process Failure. In the Event Viewer, the Application Log shows the following error:
Application 'MACHINE/WEBROOT/APPHOST/Ourapps.ac.CompanyName.com' with physical root 'C:\Ourapps.ac.CompanyName.com\' failed to start process with commandline '"" ', ErrorCode = '0x80070057 : 0.
Question: Why the same app is working under Default Websitebut not under custom website - and how can we resolve the issue?
Note:
http://Ourapps.ac.CompanyName.com/MyPublishedFolder works fine if I replaced all content of MyPublishedFolder with a simple Index.html file created on a notepad. So the issue does seem to be related to ASP.NET Core's published folder deployed to a custom website
Both the apps on the above examples are running with a No Managed Code Application Pool.
UPDATE:
Please note the same ASP.NET Core website works fine under Default Website on the same server. That means the sever has all the necessary configurations (hosting bundle DotNetCore.1.0.5_1.1.2-WindowsHosting installed etc.) for an ASP.NET Core 1.1.1 to run on IIS.
Web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\MyCoreWebApp.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false" />
</system.webServer>
</configuration>
<!--ProjectGuid: 9e4933bc-a6d0-4aa8-b34c-c6db94ed0742-->

HTTP Error 403.14 - Forbidden asp.net 5 & MVC 6 iis10

I know this question has been asked and answered a few time but those questions are slightly different and the answers to those questions do not resolve my issue.
I have a asp.net 5 & MVC 6 application that works fine in IIS Express and self hosted in WEB. However when I publish to a folder and point IIS at the wwwroot folder I get the HTTP Error 403.14 - Forbidden error.
I have tried IISReset and I do have a default root.
Requirements
Windows 7 or better
Windows Server 2008 R2 or better
Have IIS installed
Procedure
First, make sure you have the HTTP Platform Handler installed in your IIS (x86 / x64).
Publish your application to the file system and take the content of the \artifacts\bin\MyWebApp\Release\Publish folder and copy it into your IIS Server.
When configuring your application, target the wwwroot folder that you copied over.
Now you'll need to unlock the system.webServer/handlers section which can be found in IIS Manager on the server node under Configuration Editor. Search for the right section and unlock it from the right action pane.
Make sure that the App Pool is set to No Managed Code. DNX is being run as an external process. IIS doesn't need to know about what it's currently running.
Finally, create a web.config with the following content:
<configuration>
<system.webServer>
<handlers>
<add name="httpplatformhandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
</handlers>
<httpPlatform processPath="..\approot\web.cmd" arguments="" stdoutLogEnabled="false" stdoutLogFile="..\logs\stdout.log" startupTimeLimit="3600"></httpPlatform>
</system.webServer>
</configuration>
It should be running at that point.
Source

Resources