How to run Node.js application
This article contains steps how to run Node.js application on MonsterASP.NET hosting.
ASP.NET / .NET freehosting
If you don't already have our ASP.NET / .NET freehosting, sign up for FREE at https://MonsterASP.net/.
-
Initial Setup
Create a website from our hosting Control panel.
-
Create simple script
Create a simple Node.js Hello world! sample script.
hello.js
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end('Hello, world! [helloworld sample; iisnode version is ' + process.env.IISNODE_VERSION + ', node version is ' + process.version + ']');
}).listen(process.env.PORT);
Save sample script as hello.js file.
-
Upload script hello.js file
Upload script file to /wwwroot directory on hosting Website. You can use FTP/SFTP access to upload script file.
How to publish files via FileZilla Client
-
Upload configuration web.config file
To run Node.js application, you must also upload web.config file to /wwwroot directory which contains necessary configuration for Node.js.
Folder \wwwroot is website root and hello.js and web.config files must be located in this directory.
Necessary configuration file
web.config
<configuration>
<system.webServer>
<handlers>
<add name="iisnode" path="hello.js" verb="*" modules="iisnode" />
</handlers>
<defaultDocument>
<files>
<add value="hello.js" />
</files>
</defaultDocument>
<rewrite>
<rules>
<rule name="nodejs">
<match url="(.*)" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="/hello.js" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Website result in browser:
You do not need to run any command line like npm or node to host Node.js application on MonsterASP.NET.
Node modules must be uploaded to node_modules directory. You must install all required node modules locally using npm before upload application on Website.