How to execute vscode npm?
vscode Debugging node npm and nodemon
There are many ways to debug nodejs. You can read this article How to Debug Node.js with the Best Tools Available. Among them, my favorite method is V8 Inspector and vscode.
In vscode, click the spider button
to see the debug sidebar, then add the configuration
Select the environment
See the launch.json file.
When starting, select the corresponding configuration, and then click the green triangle pointing to the right
launch mode and attach mode
{ "version": "0.2.0", "configurations": [ { "type": "node", "request": "launch", "name": "Launch Program", "program": "${workspaceRoot}/index.js" }, { "type": "node", "request": "attach", "name": "Attach to Port", "address": "localhost", "port": 5858 } ] }
When the request is launch, it is launch mode Yes, this is the program started from vscode. If it is debugging, it will always be in debugging mode. The attach mode is to connect to an already started service. For example, if you have started the project outside and suddenly need to debug it, you do not need to close the started project and restart it in vscode. As long as you start it in attach mode, vscode can connect to the already started service. When debugging is over, just disconnect, which is obviously more convenient than launch.
Use npm to start in debug
Many times we write long startup commands and configurations in the scripts of package.json, such as
"scripts": { "start": "NODE_ENV=production PORT=8080 babel-node ./bin/www", "dev": "nodemon --inspect --exec babel-node --presets env ./bin/www" },
We want vscode to start and debug using npm, which requires the following configuration
{ "name": "Launch via NPM", "type": "node", "request": "launch", "runtimeExecutable": "npm", "runtimeArgs": [ "run-script", "dev"//这里的dev就对应package.json中的scripts中的dev ], "port": 9229//这个端口是调试的端口,不是项目启动的端口 },
Use nodemon to start in debug
Just use npm to start , although nodemon is used in the dev command, the program can be restarted normally, but after restarting, debugging is disconnected. So you need to let vscode use nodemon to start the project.
{ "type": "node", "request": "launch", "name": "nodemon", "runtimeExecutable": "nodemon", "args": ["${workspaceRoot}/bin/www"], "restart": true, "protocol": "inspector",//相当于--inspect了 "sourceMaps": true, "console": "integratedTerminal", "internalConsoleOptions": "neverOpen", "runtimeArgs": [//对应nodemon --inspect之后除了启动文件之外的其他配置 "--exec", "babel-node", "--presets", "env" ] },
Pay attention to the runtimeArgs here. If these configurations are written in package.json, it will look like this.
nodemon --inspect --exec babel-node --presets env ./bin/www
This is very convenient. The project can be restarted normally, the same every time it is restarted. The debugging function will be enabled.
But what should we do if we don’t want to enable the debugging function all the time?
This requires using the attach mode mentioned above.
Use the following command to start the project normally
nodemon --inspect --exec babel-node --presets env ./bin/www
When we want to debug, run the following configuration in the debug of vscode
{ "type": "node", "request": "attach", "name": "Attach to node", "restart": true, "port": 9229 }
Perfect!
The above is the detailed content of How to execute vscode npm. For more information, please follow other related articles on the PHP Chinese website!

VisualStudio is suitable for large-scale projects and enterprise-level application development, while VSCode is suitable for rapid development and multilingual support. 1. VisualStudio provides a comprehensive IDE environment and supports Microsoft technology stack. 2.VSCode is a lightweight editor that emphasizes flexibility and scalability, and supports cross-platform.

Yes, some versions of VisualStudio are free. Specifically, VisualStudioCommunityEdition is free for individual developers, open source projects, academic research, and small organizations. However, there are also paid versions such as VisualStudioProfessional and Enterprise, suitable for large teams and enterprises, providing additional features.

Cross-platform development with VisualStudio is feasible, and by supporting frameworks like .NETCore and Xamarin, developers can write code at once and run on multiple operating systems. 1) Create .NETCore projects and use their cross-platform capabilities, 2) Use Xamarin for mobile application development, 3) Use asynchronous programming and code reuse to optimize performance to ensure efficient operation and maintainability of applications.

The ways to format JSON in VS Code are: 1. Use shortcut keys (Windows/Linux: Ctrl Shift I; macOS: Cmd Shift I); 2. Go through the menu ("Edit" > "Format Document"); 3. Install JSON formatter extensions (such as Prettier); 4. Format manually (use shortcut keys to indent/extract blocks or add braces and semicolons); 5. Use external tools (such as JSONLint and JSON Formatter).

Compiling code in VSCode is divided into 5 steps: Install the C extension; create the "main.cpp" file in the project folder; configure the compiler (such as MinGW); compile the code with the shortcut key ("Ctrl Shift B") or the "Build" button; run the compiled program with the shortcut key ("F5") or the "Run" button.

To install Visual Studio Code, please follow the following steps: Visit the official website https://code.visualstudio.com/; download the installer according to the operating system; run the installer; accept the license agreement and select the installation path; VSCode will start automatically after the installation is completed.

The methods to enlarge fonts in Visual Studio Code are: open the settings panel (Ctrl, or Cmd,). Search and adjust "Font Size". Choose "Font Family" with the right size. Install or select a theme that provides the right size. Use keyboard shortcuts (Ctrl or Cmd) to enlarge the font.

How to connect to a remote server through VSCode? Install Remote - SSH Extended Configuration SSH Create a Connection in VSCode Enter connection information: Host, Username, Port, SSH Key Double-click the saved connection in Remote Explorer


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

WebStorm Mac version
Useful JavaScript development tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.