Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js and MS Azure on process.env.port variable

Tags:

node.js

azure

consider the following Node.js code:

var http = require('http');
var port = process.env.port || 1337;
http.createServer(function (req, res) {
    res.writeHead(200, { 'Content-Type': 'text/plain' });
    res.end('Hello World\n');
}).listen(port);

It does not work in Microsoft Azure, because of string value in process.env.port variable (for example: \.\pipe\e289ed7e-b57b-46bb-8bba-ad8cd1f1529cf). Why is it happening?

like image 373
Ehsan Avatar asked Dec 05 '22 03:12

Ehsan


1 Answers

The only thing should be done is to have a proper web.config file, for handling the named pipe port in Microsoft Azure. The simplest content for this file can be:

<configuration>
<system.webServer>
      <handlers>
        <add name="iisnode" path="server.js" verb="*" modules="iisnode"/>
      </handlers>
      <rewrite>
        <rules>
          <rule name="DynamicContent">
            <match url="/*" />
            <action type="Rewrite" url="server.js"/>
          </rule>
        </rules>
      </rewrite>
</system.webServer>
</configuration> 

if your initial NodeJS file is app.js, replace the server.js strings in above content with it!

like image 132
Ehsan Avatar answered Dec 23 '22 08:12

Ehsan