- Latest (22.3)
- Dev Build
- Java Reference
- Java on Truffle
- Node.js Runtime
- Java Interoperability
- Differences Between Node.js and Java Embeddings
- ScriptEngine Implementation
- LLVM Languages Reference
- Python Reference
- Ruby Reference
- R Reference
- WebAssembly Reference
GraalVM can run unmodified Node.js applications. Applications can freely import and use NPM packages, including native ones.
For the differences between running the
Installing Node.js Component #
Since GraalVM 21.1, the Node.js support is packaged in a separate GraalVM component. It can be installed with the GraalVM Updater.
$GRAALVM/bin/gu install nodejs
This installs the
npm binaries in the
Polyglot Support in Node.js #
The Node.js component is able to use the polyglot language interoperability (flag:
--polyglot) with other installed polyglot languages.
This feature is available by default in JVM mode (flag:
For polyglot access to the Ruby language, you can e.g. use this command:
$GRAALVM_HOME/bin/node --jvm --polyglot -e 'var array = Polyglot.eval("ruby", "[1,2,42,4]"); console.log(array);'
To use the polyglot capabilities of
node in the native mode (flag:
libpolyglot needs to be rebuilt first.
For this, the
native-image component and the other languages need to be installed first, before the image can be rebuilt:
$GRAALVM_HOME/bin/gu install native-image $GRAALVM_HOME/bin/gu rebuild-images libpolyglot
After a successfull rebuild, the polyglot access is also available in the
$GRAALVM_HOME/bin/node --native --polyglot -e 'var array = Polyglot.eval("ruby", "[1,2,42,4]"); console.log(array);'
Running Node.js Applications #
To run Node.js-based applications, use the
node launcher in the GraalVM distribution:
$GRAALVM_HOME/bin/node [options] [filename] [args]
node command is largely compatible with Node.js, and features additional GraalVM-specific functionalities (e.g., interoperability with Java and all other GraalVM languages).
A list of available options can be obtained with
Installing Packages Using
To install a Node.js package, you can use the
npm launcher from the GraalVM’s
npm command is equivalent to the default NPM command, and supports most of its options.
An NPM package can be installed with:
$GRAALVM_HOME/bin/npm install <package>
npm command of GraalVM is largely compatible with NPM, packages will be installed in the
node_modules folder, as expected.
npm Packages Globally #
Node packages can be installed globally using
npm and the
npm installs global packages (links to their executables) in the path where the
node executable is installed, typically
In GraalVM, while there is a
node executable in
GRAALVM/bin, this is just a link to the actual executable in the
That folder is where global packages are installed.
You might want to add that directory to your
$PATH if you regularly use globally installed packages, especially their command line interfaces.
Another option is to specify the global installation folder of
npm by setting the
$PREFIX environment variable, or by specifying the
--prefix option when running
For example, the following command will install global packages in the
$GRAALVM_HOME/bin/npm install --prefix /foo/bar -g <package>
More details about
prefix can be found in the official NPM documentation.