17106

process.env.PORT is undefined

Question:

I am trying to go to production on one of my node.js applications which runs ion windows server 2012. After a week of troubleshooting and reading everything I could get to online, the problem seems to be the "process.env.PORT" variable.

<hr />

The symptoms are as follows:

The website works fine when:

set PORT=3510 in console domain.com:3510/index.html in remote browser

However, when I type:

domain.com

I get a 404 - File or directory not found.

<hr />

When I console.log the "process.env" object at startup of my server.js, the console.log prints an object with several properties but no "PORT" property (unless I "set PORT=3510"). Without setting the port manually prior to launching the server.js, "process.env.PORT" console.logs reports undefined.

However, If manually specify the port, the server still does not work because, according to what I read, node expects "process.env.PORT" to be a named pipe and not a number.

So the problem is very specific:

How do I set the "process.env.PORT variable" on windows 2012 server so that nodejs can work with it?

Answer1:

You need to set it in the web.config file. You can set a key as "PORT" with the value you need. See the below web.config file as an example...

<configuration> <appSettings> <add key="PORT" value="3510" /> </appSettings> ...(Other configurations here) </configuration>

Recommend

  • Is there an easy way to tell how much time is spent waiting for the Python GIL?
  • Aggregations with dependent conditions on mongoDB
  • jQuery colorbox loading 2 iframes
  • Nginx - how to redirect (301) www to non-www correctly for bot http /https?
  • How to get rid of extra spaces in a textarea?
  • Cloud Functions for Firebase with custom HTTP path
  • How to upload file on another domain?
  • something very wrong with SESSIONS
  • ERROR for site owner: Invalid site key
  • VirtualDocumentRoot handling non-existent folders
  • nginx prod setup for Clojure WebSocket app
  • Accessing Windows Azure Queues from client side javascript/jquery
  • Weighted round robin dns between 2 Cloudfront distributions
  • proxy request in node.js / express
  • PHP Copy function not working
  • jwtBearer bearer token with rc-1 update to ASP.Net 5
  • Should I or shouldn't I use the CachingConnectionFactory with hornetq 2.4.1
  • Email verification using google app script and google forms
  • Typescript - Unable to get 'import' statement to function
  • PHPUnit_Framework_TestCase class is not available. Fix… - Makegood , Eclipse
  • Is there any way to access browser form field suggestions from JavaScript?
  • Sony Xperia Z Tablet not found by adb
  • How to recover from a Spring Social ExpiredAuthorizationException
  • ILMerge & Keep Assembly Name
  • Large data - storage and query
  • How do you troubleshoot character encoding problems?
  • How can I estimate amount of memory left with calling System.gc()?
  • Rearranging Cells in UITableView Bug & Saving Changes
  • WOWZA + RTMP + HTML5 Playback?
  • How to format a variable of double type
  • Unit Testing MVC Web Application in Visual Studio and Problem with QTAgent
  • Proper way to use connect-multiparty with express.js?
  • How to set the response of a form post action to a iframe source?
  • Hits per day in Google Big Query
  • How do you join a server to an Active Directory (domain)?
  • Change div Background jquery
  • Qt: Run a script BEFORE make
  • reshape alternating columns in less time and using less memory
  • How to Embed XSL into XML
  • Conditional In-Line CSS for IE and Others?