Page MenuHomePhabricator

process.env.PORT not defined
Closed, ResolvedPublic


I've followed the instructions at and used the example server.js and package.json scripts provided there.

When I run a webservice shell and launch the script with npm start, I receive the error

    throw new ERR_SOCKET_BAD_PORT(options.port);

RangeError [ERR_SOCKET_BAD_PORT]: Port should be > 0 and < 65536. Received NaN.

Clearly the javascript var port = parseInt(process.env.PORT, 10) ; is failing to identify the port.

This would presumably account for the "bad gateway" error reported by nginx when I run webservice nodejs start.

Related Objects


Event Timeline

Smith609 triaged this task as High priority.Sep 26 2018, 6:13 AM
Smith609 created this task.
zhuyifei1999 raised the priority of this task from High to Needs Triage.EditedSep 26 2018, 1:30 PM
zhuyifei1999 added a subscriber: zhuyifei1999.

process.env.PORT is only defined if npm start is invoked by webservice [something something] start, and not for webservice [something something] shell.

What's the name of this tool? Ah, I see the parent task.

I see port=1969; in your www/js/server.js. It's not going to work. will only route to the port that is assigned to you in the PORT env variable.

I added port=1969; to help with debugging; it didn't work without this line either.

Could you start the webservice via webservice nodejs start without port=1969;? I'll see what is going on

Smith609 added a comment.EditedSep 26 2018, 2:28 PM

That's interesting; having done that, the web service now starts. I wonder why it didn't this morning...
It's certainly useful to know that PORT won't be defined with a webservice shell.

Having got the "Hello World" script started, I've replaced the script with the one I actually want to run; this is still returning a 502 bad gateway, so I'm none the wiser with the parent task...

Smith609 closed this task as Resolved.Sep 26 2018, 2:30 PM