Tips for running batch files prior to debugging in VS Code

Currently, I am working on a project using Typescript, nodeJS, and VS Code.

When it comes to debugging in VS Code, I have set up configurations in my launch.json file.

{
        "type": "node",
            "request": "launch",
            "name": "Launch via NPM",
            "runtimeExecutable": "npm",
            "runtimeArgs": [
                "run-script",
                "debug"
            ],
            "port": 9229
    },
    

I am wondering if there is a way to run a batch file before starting the service. In a regular console, I would normally do this by running:

env.cmd
    npm start
    

Answer №1

If you want to ensure a specific task is completed before debugging, consider adding it as a "preLaunchTask" with a unique identifier in your launch.json file. This task can be of the "shell type", allowing it to run as a shell command.

For example, a custom build:test task in your launch.json:

 {
    "type": "npm",
    "script": "build:test",
    "identifier": "buildtest",
    "group": {
        "kind": "test",
        "isDefault": true
    }
}

Then define the related debug task:

{
    "type": "node",
    "request": "launch",
    "name": "Mocha Tests",
    "preLaunchTask": "buildtest",
    "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
    "args": [
        "-u",
        "tdd",
        "--timeout",
        "999999",
        "--colors",
        "${workspaceFolder}/temp/test/index.js"
    ],
    "internalConsoleOptions": "openOnSessionStart"
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Integrating Vimeo videos into Angular applications

I am attempting to stream videos using URLs in my Angular application. Every time I try, I encounter the following error: Access to XMLHttpRequest at 'https://player.vimeo.com/video/548582212?badge=0&autopause=0&player_id=0&ap ...

After installing Node using nvm, Node and npm are not being recognized

To begin with, I installed nvm. Following that, I attempted nvm-v to check the version. Once that was successful, I proceeded to install node.js using nvm install 6.10.0 The installation was also successful. However, when I tried running npm-v or node- ...

The Django application encounters difficulty locating a third-party script within the node_modules directory

Currently, I am working in a development environment on Windows 10 with debug mode set to True. After installing node and npm, I ran npm microm from the root folder of my project. This action created a node_modules subfolder, within which there is a micro ...

Having trouble reading properties of undefined (specifically 'listen') during testing with Jest, Supertest, Express, Typescript

Issue: While running jest and supertest, I encounter an error before it even gets to the tests I have defined. The server works fine when using the start script, and the app is clearly defined. However, when running the test script, the app becomes undefi ...

Exploring the potential of AssemblyScript in creating immersive WebXR

I have been exploring three.js and webXR for some time now, and I wanted to incorporate it into assembly script. While I know how to make webXR work in TypeScript, I encounter an error when trying to use it in assembly script with the import statement. Her ...

Error: Virtual script not located; possibly absent <script lang="ts" / "allowJs": true / within the jsconfig.json.volar

https://i.sstatic.net/dFaVQ.png I noticed an error in my footer component in VueJs (TypeScript template) as depicted by the image showing blue squiggly lines. ...

How to toggle visibility of multiple div elements in ReactJS

When working in react-js, I encountered a situation where two div elements and two buttons were used. Clicking the first button displayed the first div and hid the second div. Conversely, clicking the second button showed the second div and hid the first d ...

What could be causing the TypeScript class property to be undefined?

Below is the code snippet I am working with: class FeedbackController { public homePage(req, res){ this.test(); res.send('Welcome to feedback service'); } private test(){ console.log('test called'); } } export de ...

encountering a hiccup when attempting to install a package on a

Encountered an error while trying to install a package. All other packages were installed smoothly except for this one. How can I resolve this issue? Changing the flag to -g (globally) makes it work, but I need it to be in my project. npm install --sav ...

What is the best way to safely distribute the same npm package with multiple contributors?

Imagine a collaborative open source project with multiple contributors working on it. As the project progresses, these contributors need to publish their work to the NPM registry. But how can this be done securely when multiple people are involved? The ow ...

Using JavaScript to generate dynamic folders in Alfresco is not functioning as expected

Working with Alfresco 4.0.d community edition (also tested on Alfresco 4.0.c) on an Oracle Linux 64-bit virtual machine using Firefox. I've been developing a script to dynamically create sub-folders as new items are added to a space/folder via a rule ...

Manipulating data with Angular 2 services: accessing and updating values

This code snippet is all about managing an array in Angular. The Injectable decorator is used to define a service called Svc with methods for setting and getting column definitions. import { Injectable } from '@angular/core'; @Injectable() ...

Performing a test on API GET Request with Playwright

I've been attempting to verify the GET status using this particular piece of code. Regrettably, I keep encountering an error message stating "apiRequestContext.get: connect ECONNREFUSED ::1:8080". If anyone has any insights or suggestions on how to re ...

``Should one prioritize the use of Generics over Inheritance, or is there a better way

We are currently in the process of implementing new contracts for our icons system, and we have encountered a debate on which approach is more preferable. Both options result in the same interface: Using Generics -> Although the interface may be less ...

What is the best way to include a new attribute in a TypeScript internal object?

I am trying to include a property declaration in the window.history object, but I received a TypeScript error message This is my code: const historyInstance = createHashHistory(); // npm hoistory module window.history.historyInstance = historyInstance; / ...

What is the reason for using 'Input' as a type instead of referring to it as a value? TS 2749

The file format is correct as .tsx, however, there seems to be an issue with using HTMLInputElement instead of Input. In my opinion, it should be Input since it relates to the assigned value. Can you help identify the problem in the code snippet below at l ...

Executing NPM task and converting arguments into strings

I am attempting to execute NPM tasks with arguments to add flexibility to my NPM build configuration. Here are my scripts: "styles": "node-sass", "build:styles": "npm run styles -- --source-map false --output-style compressed --output ./public/styles ./b ...

Determine the maximum and minimum numbers by inputting a number and utilizing jQuery

<script type="text/javascript"> function findLargestNumber() { var number1, number2; number1 = Number(document.getElementById("N").value); number2 = Number(document.getElementById("M").value); if (number1 > numb ...

Troubleshooting Appium error management is ineffective

As a newcomer to appium, I might have made some mistakes. I'm encountering a problem with appium while using wdio and jasmine. it('wtf', (done) => { client.init().element('someName').getText() // ^ here ...

Encountering a compilation error due to a Typescript assignment

While working with Typescript, I encountered a compilation error in the code shown below: console.log('YHISTORY:login: data = '+data); let theData = JSON.parse(data); console.log('YHISTORY:login: theData = '+JSON.stringify(theData)); ...