ASP.NET Core + Node.js
Table of Contents
Introduction
JavaScript and TypeScript in Visual Studio In Visual Studio 2022 and later, there is a new JavaScript/TypeScript project type (.esproj) called the JavaScript Project System (JSPS) that allows you to create standalone Angular, React, and Vue projects in Visual Studio.
You can create JavaScript/TypeScript projects in Visual Studio. While Visual Studio Code can be used for standalone JavaScript/TypeScript applications, the advantage of Visual Studio is its ability to manage projects as a whole, especially in cases where, for example, the front end is Vue.js and the back-end API is ASP.NET Core. Visual Studio's text editor also supports both JavaScript/TypeScript (including .tsx in addition to .js and .ts), and IntelliSense works as well.
Overview
To enable npm in Visual Studio, you need to follow a few steps. Visual Studio provides Node.js support, and npm can leverage this to manage and install packages. Follow these steps to configure npm for use in Visual Studio.
Steps
- Access the Node.js official website and download the Node.js Prebuilt Installer.
- Run the installer and follow the installation instructions.
- After installation, open a command prompt or terminal and run the following commands to confirm that the installation was successful.
node -v
npm -v
If the version numbers are displayed, it's OK.
※It is unclear if this procedure is the best. Microsoft's documentation (Install Node.js on Windows) recommends installing nvm-windows.
In addition to choosing whether to install on Windows or WSL, there are other choices to make when installing Node.js. Since versions change very quickly, we recommend using a version manager. Often, you will need to switch between multiple versions of Node.js based on the needs of the different projects you are working on. Node Version Manager (commonly referred to as nvm) is the most common way to install multiple versions of Node.js, but it can only be used on Mac or Linux and is not supported on Windows. Instead, we recommend installing nvm-windows and using it to install Node.js and Node Package Manager (npm). You should also consider alternative version managers, which are discussed in the next section.
References
JavaScript and TypeScript in Visual Studio - Visual Studio (Windows) | Microsoft Learn Manage npm packages in Visual Studio
If your project doesn't already contain a package.json file, you can enable npm support by adding a package.json file to your project.