Arcade/JS testing in VS Code: How to run simple scripts?

1080
3
Jump to solution
03-03-2022 10:29 AM
Bud
by
Notable Contributor

When writing Arcade scripts, I think it would be helpful to do testing in an IDE beforehand, if the script doesn't use any Arcade-specific functions (or if it does, temporarily remove/fake out those parts). 

For example, define a polyline array manually...

var paths = [[[0,5,null],[10,10, null],[30,0, null],[50,10, null],[60,10, null]]]

...loop through the vertices, do some stuff, and output results as text.

So, I want to use VS code to do that testing...by running the Arcade expression as if it were JavaScript . I know Arcade isn't  the same thing as JS, but I think it's close enough for the testing I want to do.
 
Question:
 
Has anyone had any success running basic JS scripts in VS Code? That might be a dumb question, but I really have no idea where to start.
Unlike Python, it doesn't seem like you can just  type some JS like  console.log('Hello World');  and then run the code to output some text.
 
I tried searching the web and I got a bunch of results about node.js -- which I have installed. Unfortunately, I still can't figure out how run a basic script, such as print "Hello World".
 
Would someone be able to point me in the right direction?
Thanks.
0 Kudos
1 Solution

Accepted Solutions
Luke_Pinner
MVP Regular Contributor

With node.js installed, in VS Code either open the folder containing your .js file (File -> Open Folder...) or open your .js file directly (File -> Open File...)

  • with the folder open - click Run->Add Configuration... pick node.js, close the launch.json file then select your .js script in the sidebar to open it in the editor and Ctrl-F5 (or Run -> Run Without Debugging) to run.
  • with the file open, Ctrl-F5 to run, pick node.js.

The advantage of opening the folder rather than the file is that you save your run config and don't have to set it up every time.

View solution in original post

3 Replies
DavidPike
MVP Frequent Contributor

Not exactly what you mean but may be helpful if you've not come across it Playground | ArcGIS Arcade | ArcGIS Developer

Luke_Pinner
MVP Regular Contributor

With node.js installed, in VS Code either open the folder containing your .js file (File -> Open Folder...) or open your .js file directly (File -> Open File...)

  • with the folder open - click Run->Add Configuration... pick node.js, close the launch.json file then select your .js script in the sidebar to open it in the editor and Ctrl-F5 (or Run -> Run Without Debugging) to run.
  • with the file open, Ctrl-F5 to run, pick node.js.

The advantage of opening the folder rather than the file is that you save your run config and don't have to set it up every time.

Bud
by
Notable Contributor

Yes! That worked!

I used the folder option you mentioned.

Bud_0-1646362983495.png

Thanks!


Related: Idea: Arcade Extension for Visual Studio Code

0 Kudos