Skip to content

Using modern JavaScript features in scripts

The default JavaScript engine is Nashorn, which is based on ECMAScript 5.1. However, you can use modern JavaScript features by switching to the GraalVM JavaScript engine.


GraalVM enables you to use modern JavaScript features such as:

  • let and const for variable declarations
  • Arrow functions
  • Template literals
  • Destructuring
  • Classes

To use the GraalVM JavaScript engine, you need to be running Imposter v3.35.0 or later, and install the js-graal plugin.

Install plugin

Option 1: Using the CLI

Note This option requires the Imposter CLI version 0.37.0 or later.

To use this plugin, install it with the Imposter CLI:

imposter plugin install -d js-graal:zip

This will install the plugin version matching the current engine version used by the CLI. The next time you run imposter up, the plugin will be available.

Option 2: Install the plugin manually

To use this plugin, download the ZIP file from the Releases page.

Enable it with the following environment variable:


Using the plugin

To use GraalVM, you need to specify the js-graal engine as the JavaScript plugin. You can do this by setting the environment variable IMPOSTER_JS_PLUGIN to js-graal:

export IMPOSTER_JS_PLUGIN=js-graal


For examples, see the examples/graal directory in GitHub.

Note Complete the prerequisites first.

Simple example

Start the mock server with the js-graal engine:

imposter up examples/graal/simple -e IMPOSTER_JS_PLUGIN=js-graal

Send a request to the mock server:

curl -i http://localhost:8080?name=Ada

Hello Ada

Advanced example

See the examples/graal/es6 directory for an example of using modern JavaScript features in a script.