GraalVM JavaScript Interpreter

Jakob Jenkov
Last update: 2022-02-09

The GraalVM has a JavaScript interpreter you can use to run JavaScript code - both from the command line and from inside your Java applications. The GraalVM JavaScript interpreter is ECMAScript 2021 compliant. GraalVM also has a Node.js runtime you can use - which activates the JavaScript interpreter from the command line like you might be used to from Node.js. In fact, GraalVM uses the original Node.js source code, but has replaced the V8 JavaScript engine with the GraalVM JavaScript interpreter internally. GraalVM also has NPM included.

The js Command

GraalVM comes with a built-in js command (in the [graalvm-home-dir/bin] directory) which can execute JavaScript. You can execute the js command from the command line, similar to this:

C:\data\downloads\graalvm\graalvm-ce-java11-20.3.0\bin\js

After executing the js command you can start typing in JavaScript code which then gets executed immediately (when you press return).

You can also pass a file name to the js command. The js command will then load that file and execute it as a JavaScript file. Here is how that would look:

C:\data\downloads\graalvm\graalvm-ce-java11-20.3.0\bin\js script.js

Installing Node.js

The GraalVM Node.js command is not installed along with GraalVM in the base GraalVM distribution. You have to install Node.js separately. Here is how that looks:

C:\data\downloads\graalvm\graalvm-ce-java11-20.3.0\bin\gu install nodejs

Running this command will install the node and npm commands. You can then use them like you would with a normal Node.js and NPM installation.

Jakob Jenkov

Featured Videos

Java ForkJoinPool

P2P Networks Introduction




















Advertisements

High-Performance
Java Persistence
Close TOC
All Tutorial Trails
All Trails
Table of contents (TOC) for this tutorial trail
Trail TOC
Table of contents (TOC) for this tutorial
Page TOC
Previous tutorial in this tutorial trail
Previous
Next tutorial in this tutorial trail
Next