Ad

Visual Studio Node.js Express 4 Application Server Quits

- 1 answer

Googling didn't get me vary far with this so I wanted to make a post about it.

In Visual Studio 2017 if you create a new Node.js Express 4 Application project, build it and debug it then the Node.js server will just crash and exit before you can read any output from the CMD window that it was running in.

Checking the log file C:\Users\matt\AppData\Local\Temp\vscode-node-debug2.txt yielded no usable information for me. What was causing it to crash and how can it be fixed?

Ad

Answer

First, be sure you update your npm packages in Visual Studio by performing the following steps.

  1. In solution explorer, expand the npm node.
    Solution Explorer

  2. Right click and choose the appropriate option.
    a. Install Missing npm Packages
    b. Update npm Packages
    NPM Packages

That didn't fix the issue but it doesn't hurt. Now if you rebuild your project and debug it by pressing ctrl + F5 then it will pause on the error that is causing the Node.js server to crash.

Node.js Server Error

So, The server is having trouble binding to port 1337. I'm assuming that's because it's such a low port number and we're running Visual Studio as a regular user and not as an administrator. To change the port number to a higher value you can edit the app.js file in Visual Studio.

I Changed the following line
Setting the Port 1
to
Setting the Port 2

Now, if you save everything, rebuild the project and debug it by clicking the debug button or pressing F5 the server will successfully start. The browser will still be directed to port 1337 instead of port 65073 though. After changing the port number in the address in the browser the page loads fine.

I'm not sure how make it open to the port we set. I'll update this post if I figure that part out.

Ad
source: stackoverflow.com
Ad