I have built an API using Loopback. Now that it's time to host it on my Windows machine, Googling turned up two distinct options: 1) using NSSM to create a Service, or 2) using IISNode, a IIS module, to host the API using an IIS process. Since the benefits of using IIS seemed too strong to ignore, I chose that option.
The loopback documentation states that iisnode can be used to host a loopback api, but then fails to provide any guidance on the topic.
Iisnode documentation also has a few very basic examples, some based around Express (which loopback is built upon), but doesn't make it clear how to adapt a loopback application for use with iisnode. In all of their simplistic examples, the main node file is located at the root level of the node project. Loopback, however, keeps its at "~/server/server.js". This makes it unclear about where to place and configure the web.config file necessary for iisnode to work.
Is anyone aware of a decent tutorial or walk-though for hosting a Loopback project in IIS using iisnode? All I found are vague articles stating to the effect of "well...it should work." Has anyone successfully hosted a loopback project using iisnode?
Make sure you follow this small check. Loopback hosting on web servers has a known issue(Not exactly an issue, but a protection feature, which can trip up first time deployer):
https://github.com/masonkmeyer/loopback-azure
The app.start() is called only when loopback's server.js is invoked directly. But webservers like IIS usually invoke the main script by requiring it. The solution suggested above is a little inelegant, in the sense that it does not guarantee that app.start will be called only after boot completes setting up rest endpoints.
Otherwise the web.config is pretty straight forward. The following helped me with the configuration a bit:
https://tomasz.janczuk.org/2011/08/using-url-rewriting-with-nodejs.html
I'm not sure that you need a Loopback specific tutorial to help you out here. You just need to modify your Web.config.
Inside your Web.config there needs to be an iisnode handler. This instructs IISNode which file is the main file in your project. To direct traffic to your server file path simply change the path attribute on the handler.
<handlers>
<add name="iisnode" path="/server/server.js" verb="*" modules="iisnode"/>
</handlers>
I've created a couple different walkthroughs for setting up an IISNode app with Express but they are applicable to really to anything being setup with IISNode.
This answer
Related
I have node js api and it works when starting using nodemon from node terminal. Now I want to deploy it to IIS. How can I do it? Please reply, it is important.
To run Node.js apps on IIS on Windows, iisnode module is needed. Please follow this article to get going. Primary requirement to run your Node.js app on Windows is the iisnode module. If you follow the instructions carefully, you can get it working pretty quickly.
PS: You would also need to assign user IIS_IUSRS READ permissions to the folder (and its parent folder) which contains your Node.js API sources. web.config which mentions the iisnode module is very important for everything to work smoothly.
I followed the Angular2 Quick start example and used live-server to run it. It works fine.
I created then a web site in IIS and set the virtual directory to the directory where I have the index.html file. When I run the website I get the following error. The error happens when the IIS tries to server app.ts.
How can run the Angular2 app in IIS?
The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.
UPDATE:
Solution: I created a new web.config file and added the following snippet of code to add the MIME type. This will be used by the IIS as the local web app settings.
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".ts" mimeType="application/x-typescript" />
</staticContent>
</system.webServer>
</configuration>
By convention, it is not advised to directly serve TypeScript (.ts) files. This is why IIS doesn't enable this by default. The quickstart tutorial also explicitely mentions this halfway the page, on section What's wrong with this?, where it states the following:
We were up and running in a hurry and we could explore Angular in this manner for quite some time. For a number of reasons this isn't a good approach for building an application:
Transpiling TypeScript in the browser becomes tediously slow when our app grows beyond a few files. We certainly won't do that in production. We should learn to compile locally and push the generated JavaScript to the server. We'll need some tools for that.
So if you take a couple of minutes more and finish the tutorial, it'll work out for you just fine without having to bother with IIS configuration.
That being said, if you truly want it, it is possible. Like mentioned in other comments, you can add a MIME type for .ts files in IIS. In the SO question What's the MIME-Type of TypeScript it is explained as well.
try to register a .ts mime type
Add a MIME Type (IIS 7)
Also, this SO seems like a good explanation
I'm running a Node.js server as API for my mobile app on a Windows Azure Website. And I'm having some trouble with it due to the needed web.config - but I couldn't find any really helpful documentation about it. Everything I can find is googling for specific problems on it and with a bit luck I can use the config snippets.
is there any general documentation about the contents the web.config can contain and their meaning?
in the start I had the problem that errors were modified by IIS to a general error. But since it's a REST API I want the HTTP status codes to be returned. I got around that with the <httpErrors existingResponse="PassThrough" /> element, but it doesn't seem to work for every error.
The only documentation I found so far are example configuration files of the iisnode module.
If you see the following error:
web.config not found in project, to create a project to deploy to
Windows Azure you must create a Windows Azure Node.js project.
....you may have created the wrong type of Visual Studio Project. You want a "Windows Azure Node.js Application" not a "Node.js Web Application". The former creates a few extra files that are needed for Azure (Web.cloud.config & Web.config).
You may be able to create a dummy VS project of the correct type and then copy these files into your existing project. Alternatively create a new project of the correct type and copy your source files into the new project.
Create Azure Basic Node.js Express Application
I have successfully tested the vline-node example locally, but would like to push it out to a server. I have tried to install the example as an application on an IIS8 website, placing the example code under wwwroot. I have done tried this both within the root and inside a virtual directory, pointing to the views folder. I am able to login to the application from a browser on the server, although, since javascript is turned off on the server browsers for security, so functionality is missing.
However, when I try to access the site from a remote browser I am not able to login. Actually, I can see that there is something wrong with my paths, as the include files are not found.
The more I've thought about this the more confused I've become. I'd like to run this under IIS, but wonder if that makes sense. Can someone offer a clean solution for hosting the vline-node example on a Windows Server, ideally under IIS?
Since you are using the node example, you'll need to make sure that node is actually running on your IIS server. Here's a SO response that may be helpful: How to run Node.JS server for a web application?
Note that in our node example the "main" file is vline-node.js, so use that in place of the app.js that is mentioned.
I am coming from Microsoft world so please bear with me on this. I was told I could install node.js and use that as a web server instead of IIS. This is a very small business application. In IIS I can create virtual directory and point to the location of the web page and everything works just fine. Based on very little I read, I have few questions;
Is it possible to run node js as a windows service or any other form so that it runs for ever? I did find the forever package that I think I can use.
In IIS, I can create virtual directory set the port and thats it, I have myself a website.
I do not see any examples where I can use a directory where I have a web page, written in java script and point it to run as a web site. All the examples have some thing like server.js and that runs and routes the call. what is the other way to host web sites and use node.js to simple run as a fast web server.
I was told I could install node.js and use that as a web server instead of IIS.
This is true, but as you already found out then you are in charge of providing for things that IIS was already doing for you (e.g. automatically restart on reboot, or on crashes, hosting multiple sites by creating virtual folders, et cetera.)
You can indeed get all of these things worked out in Node.js and there are several libraries that help on each of these areas. It's not too hard but you'll need to do a bit of researching.
You can also run Node.js behind IIS. Take a look at iisnode http://tomasz.janczuk.org/2011/08/hosting-nodejs-applications-in-iis-on.html
Is it possible to run node js as a windows service or any other form so
that it runs for ever?
The library Forever takes care of restarting the site when it crashes...but I don't know if you can run it as a Windows Service. I haven't tried that.
In IIS, I can create virtual directory set the port and thats it,
I have myself a website.
I assume you are talking about a site that serves static HTML files, right? If that's the case that's very easy to support in Node.js either writing your own web server or using Express.js to serve static files.
I do not see any examples where I can use a directory where I have a web page,
written in java script and point it to run as a web site. All the examples
have some thing like server.js and that runs and routes the call.
Here is an extremely simple example to serve plain HTML files in Node.js https://gist.github.com/2573391 Don't use this in production, though. It's just an example and it does not have any kind of error handling or security.
what is the other way to host web sites and use node.js to simple run
as a fast web server.
As others have said, you should look into Express.js http://expressjs.com/ It provides some of the infrastructure that you are very likely going to need when building traditional web sites.
You say you're running a "very small business application" behind IIS. Unless it's written for Node.js (in JavaScript), it won't work.
There are no examples pointing to a directory and running that as a website, because that's not how things are done in Node.js. You write a Node.js-application and pull in a webserver-library.
Put simply, In Node.js, you don't embed the appliation in the webserver; you embed the webserver in the application.
When I used node.js, I redirected HTTP requests by a proxy server, nginx. I don’t know if you can directly bind node.js as an HTTP server, but for what’s it worth, nginx is pretty nice!
First things first, allow me to share an introduction. IMHO you should take this decision ( of moving from IIS to nodeJS) by adding various parameters. I belong to the Java & PHP community yet I use NodeJS to achieve extremely specific implementation where NodeJS perform the fastest ( fast IO, AJAX-JSON responses & more ). As you are coming with a Microsoft background you should bare with less comfortable solutions.
Yes, its possible to run NodeJs as a windows service and Forever will do fine.
and yes you can create "Virtual Directories" but by creating symbolic links to each of your customer's web site.
I recommend to take a good look at bouncy & express, If you're willing to take this step then these packages is just what you need.
Cheers!