2

I'm trying to run through a simple CRUD node module using VS Code.

A simplified version of the module looks like this:

const getAll = () => {
  // return all elements
}

const saveElement = element => {
  // takes an object and goes through it and saves it
}

const removeElement = id => {
  // deletes the element with the passed id or returns false
}

const readElement = id => {
  // returns the element from the data
}

I'm using yargs to get the arguments for the app, but also I'm using commands to call each method, like this

node app.js remove --id="123456789"

The launch.json in VS Code looks like this:

{
  "version": "0.2.0",
  "configurations": [       
    {
      "type": "node",
      "request": "launch",
      "name": "Test Remove",
      "program": "${workspaceRoot}/app.js",
      "args": [
        "--id='123456789'"
      ]
    }
  ]
}

What I've been unable to do is adding the specific remove, add, list, read commands into the debugger to check those methods, because without those the app runs just with the arguments and it returns a log I added indicating that the command passed is not recognized.

I looked in the VS Code docs, but I didn't found anything that relates to what I'm trying to do.

1 Answer 1

3

Ok got it. It's quite simple actually. Just pass the module's specific command in the args array. The only caveat is that the order in the array has to be the same used in the CLI. So if the idea is to run this:

node app.js remove --id="123456789"

The launch.json object should look like this:

{
  "version": "0.2.0",
  "configurations": [       
    {
      "type": "node",
      "request": "launch",
      "name": "Test Remove",
      "program": "${workspaceRoot}/app.js",
      "args": [
        "remove",
        "--id=123456789"
      ]
    }
  ]
}

Changing the order inside the args array will result in an unwanted behavior.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.