Tips for debugging Arcade scripts in VSCode/Node.js

03-11-2022 05:41 AM
Labels (1)
Frequent Contributor

What are some tips/tricks for debugging Arcade scripts in VS Code/Node.js?
(assuming that the Arcade script is fairly vanilla -- as in, it doesn't use many Arcade-specific functions  that need to be stripped-out)

For example, Arcade uses console(), whereas VS Code/Node.js uses console.log().

  • Solution:
    In VS Code, put this line at the top of the script: 
    console = Object.assign(console.log, console); 
  • That will assign console.log() to console(). Which means I can use the console() script in both programs -- without constantly doing "find and replace" on .log.
  • Note: Only use that line in VS Code; it won't work in Arcade (and isn't needed in Arcade).

Any other ideas?
(I'm a novice, so it's possible the console.log() thing is wonky...I'm just trying to learn, and not get too frustrated while I'm at it 🙂

Related: Idea: Arcade Extension for Visual Studio Code

0 Kudos
2 Replies
MVP Honored Contributor

Personally, I almost always keep one of these two things up in a tab:

  1. The Arcade Playground
  2. A "Test Space" dashboard pre-loaded with all sorts of datasets, widgets, and Data Expressions

As I work on a script in VSCode, I routinely copy it into one of these test spaces to get feedback. It's not perfect, but it works well enough.

- Josh Carlson
Kendall County GIS
Frequent Contributor

By the way, the keyboard shortcut for auto-formatting code in VS Code is: Shift + Alt + F.

How do you format code in Visual Studio Code (VSCode)?

0 Kudos