Create Node.js Web Application in Visual Studio


Here, you will learn how to create a Node.js web application using Visual Studio.

First of all, You must install Node.js development workload for Visual Studio. If you need to install the workload but already have Visual Studio, go to Tools > Get Tools and Features..., which opens the Visual Studio Installer. Choose the Node.js development workload, then choose Modify.

Create a new project by clicking on New Project.. on the start page or FILE menu. This will open a New Project dialog box as shown below.

Select Node.js Template in Visual Studio

As shown in the above figure, from the New Project dialog box, expand Installed -> Templates -> JavaScript -> Node.js in the left pane. Select the Blank Node.js Web Application in the centre pane, enter a project name and a location and click OK. This will create a Node.js web application project as shown below.

Node.js web server project in Visual Studio

As you can see, it has created server.js, which creates a web server listening on the 1337 port and sends the "Hello World" text as a response to any http request.

Press F5 to run the web project. It will open the command prompt and the browser, as shown below.

Create Node.js web server using Visual Studio
Node.js Web Application

So now, you can send different responses based on the requested URLs the same way as shown in the Node.js web server section.