1

When I'm updating (and testing) a specific page in my application, I need to stop the server, start again with node server.js, switch to the browser window, hit F5 and switch back to the terminal to see the output. This takes a lot of time.. :)

Is there a way I can start Node with something like this:

node server.js -url /my_page

so I can directly see the output as if someone hit the page from their browser?

I found this question but I guess it's included in the server code so it needs to be updated each time too. It is a solution, but I wonder if there is a faster way to do this.

Thanks,

Edit:

With curl, I'm getting this error:

$ node server.js & curl 'http://localhost:5000/my_page'
[2] 12824
curl: (7) Failed to connect to localhost port 5000: Connection refused
[1]   Terminated              node server.js
$ Listening on port 5000

Notice the last line, is it executing curl before the server is started?

Community
  • 1
  • 1
jeff
  • 13,055
  • 29
  • 78
  • 136

1 Answers1

2
node server.js & curl 'http://localhost/my_page'

This starts the server in the background, then immediately uses curl to make an HTTP request.

The server will still be running after this. You can bring it to the foreground (e.g. in order to kill it) with fg. Alternatively just run the two commands (without &) in separate terminals (or screens).

If the server doesn't start fast enough, just add a delay:

node server.js & sleep 1 ; curl 'http://localhost/my_page'
Community
  • 1
  • 1
OrangeDog
  • 36,653
  • 12
  • 122
  • 207
  • OK. So the `EADDRINUSE` error was because the previous instances were still open. Thanks so much for your help! – jeff Dec 07 '16 at 16:07