Support Forums

Running JavaScript code using the Node.JS interpreter

Support for all customers who have purchased a PrimalScript product license. This forum does not offer a response time guarantee.
Forum rules
DO NOT POST SUBSCRIPTION NUMBERS, LICENSE KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.
User avatar
rodriguennr
Posts: 5
Joined: Sun Sep 27, 2015 2:11 am

Running JavaScript code using the Node.JS interpreter

Postby rodriguennr » Fri Jan 15, 2016 12:05 pm

PrimalScript 2015, v7.1.74, 64bit
Operating system: Windows 10-64bit

I am wondering whether it is possible to run standalone JavaScript codes in PrimalScript and output the result to the PrimalScript "Output" window. For example, I want to run the following code and I need to use the Node.js or any other interpreter except the Microsoft JScript runtime. How do I set this up so that the result of the script is displayed on the PrimalScript "Output" window?

Many thanks in advance.

var player1={name:"Fred", score:"1000", rank:20};
var player2={name:"Sam", score:"30000", rank:3};
 
function playerDetails(){
console.log(this.name + " has a rank of " + this.rank +
" and a score of " +this.score)
}
 
player1.logDetails=playerDetails;
player2.logDetails=playerDetails;
 
player1.logDetails();
player2.logDetails();
User avatar
DevinL
Site Admin
Posts: 592
Joined: Mon Aug 17, 2015 2:25 pm

Re: Running JavaScript code using the Node.JS interpreter

Postby DevinL » Fri Jan 15, 2016 12:25 pm

You can use a custom interpreter by navigating to Options -> Environment -> Languages and selecting JavaScript. Off to the right you'll see a section for the Script Interpreter:

Custom_Interpreter.png
Custom_Interpreter.png (26.88 KiB) Viewed 3082 times
DevinL
SAPIEN Technologies, Inc.
User avatar
rodriguennr
Posts: 5
Joined: Sun Sep 27, 2015 2:11 am

Re: Running JavaScript code using the Node.JS interpreter

Postby rodriguennr » Sun Jan 17, 2016 5:39 am

Ok, I should have mentioned that I had already tried this suggestion but it still doesn't work. PrimalScript still picks the Microsoft JScript interpreter. This then fails to execute any valid JavaScript code successfully.

I have tried various arguments and Initial Directory paths to no avail. I have tried the following arguments
$file$
node $file$
$filename$ along with $filedir$

Executing my script from the Windows command line using the Node.JS interpreter works without issue as seen in the below screenshot.

It must be a simple setting somewhere but I have been able to figure this out. Please help! Anyone?
Attachments
CommandLine_NodeJS.png
CommandLine_NodeJS.png (28.17 KiB) Viewed 3060 times
JavaScript_Interpreter.png
JavaScript_Interpreter.png (262.97 KiB) Viewed 3060 times
User avatar
DevinL
Site Admin
Posts: 592
Joined: Mon Aug 17, 2015 2:25 pm

Re: Running JavaScript code using the Node.JS interpreter

Postby DevinL » Tue Jan 19, 2016 11:41 am

I'm sorry about that, I said JavaScript but JScript has the .js extension associated to it. The easiest way to fix this is to instead modify the JScript settings like so:

2016-01-19_10-38-13.png
2016-01-19_10-38-13.png (28.11 KiB) Viewed 3019 times


With these settings I had no issue running a basic console.log('This is a test.'); file.
DevinL
SAPIEN Technologies, Inc.
User avatar
rodriguennr
Posts: 5
Joined: Sun Sep 27, 2015 2:11 am

Re: Running JavaScript code using the Node.JS interpreter

Postby rodriguennr » Tue Jan 19, 2016 1:54 pm

Perfect! This works now with the above settings. In fact I went into the JScript options and disassociated the JS extension from JScript and back to the JavaScript options, I have associated the JS extension with JavaScript. Thank you.

Return to “PrimalScript”

Who is online

Users browsing this forum: No registered users and 3 guests