3

Port 8010 is specified in app.json, running node index.js starts the service on port 8010. NTVS starts it on a randomly assigned port each time I start the service.

I have little experience with it, but have recently been give an large Nodejs/Express/Kraken/Angular code base to work with. The first thing I did was install NTVS (Node tools for Visual Studio) Why? Because Visual Studio is what I'm familiar with

I created a new project from existing source, start the code, it runs and works but it starts on a different randomly assigned port number each time.

Then I added values for node and debug ports on the Projects config enter image description here

This will start the debugger listening on that port enter image description here

but the app will start on a different portenter image description here

If I run in release mode, the debugger still starts on 8001 and the service starts listening on some random port that isn't 8000 or 8010.

So, I've tried running with no ports specified in the project setting, and with ports in the project settings.

Anyone any idea what I need to do to get the app started on the port that's specified in app.json?
Thanks

Update
The app is using Kraken. Kraken seems to take port config from app.json and app-development.json files. This all works as expected when running dorectly with node, and even through WebStorm (I have an evaluation edition)

The code in the index.js to start the app doesn't pass a port directly to kraken

kraken.create(app).listen(function (err) {
    if (err) {
        var log = require('log4js').getLogger(loggerName);
        log.error(err.stack);
    }

The app object has a configure method, but this doesn't seem to do anything with the port.

Binary Worrier
  • 50,774
  • 20
  • 136
  • 184
  • When you're creating an httpServer what port do you use? env.process.PORT? Have you tried hardcoding your port? – Vsevolod Goloviznin Nov 25 '14 at 14:25
  • @VsevolodGoloviznin: Not sure what you mean. When I run this from the command line, it picks up the port from the app.json file under the config folder, I change the port there, it runs on that changed port. I _think_ express takes the port from there. To be honest I'm not sure, like I said I've just been handed this, I haven't worked on it up to now. **BIG** learning curve for me! – Binary Worrier Nov 25 '14 at 14:29
  • 1
    in your app.js (or server.js) you have `app.listen(process.env.PORT, handler)` try just hardcoding your value there. I also had problems with NTVS not taking the port into account, I'm supplying it through my settings file like this and everything works: `app.listen(settings.env.port || process.env.PORT, handler)` – Vsevolod Goloviznin Nov 25 '14 at 14:31
  • @VsevolodGoloviznin: This is it! Add your comment as an answer and it's yours, thanks. – Binary Worrier Mar 26 '15 at 15:19

3 Answers3

1

Try hard-coding the port when you create the server.

kraken.create(app).listen(53530, function (err) {
    if (err) {
        var log = require('log4js').getLogger(loggerName);
        log.error(err.stack);
});
Vsevolod Goloviznin
  • 12,074
  • 1
  • 49
  • 50
  • Dude I am metaphorically buying you a metaphorical beer as we speak (metaphorically). Thanks (actual thanks, not metaphorical thanks). – Binary Worrier Mar 26 '15 at 15:53
1

Add an entry in environment variables textbox, in your project properties dialog.

PORT:8000

This will be set into process.env.PORT.

Dale K
  • 25,246
  • 15
  • 42
  • 71
0

The "Node.js port:" in project properties simply sets the environment variable "PORT" before starting the node process.

This would be the equivalent of:

SET PORT=1234
node myapp

Kraken seems to use process.env.PORT in addition to command arguments and a configuration file. See https://github.com/krakenjs/kraken-js/issues/142

Simon
  • 390
  • 2
  • 9