Skip to content

caoccao/Javenode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Javenode

Maven Central Discord Donate

Linux Build

Javenode is Java + V8 + Node.js. It is a Node.js simulator with Java in V8.

Javenode is an extension of Javet (Java + V8). It aims at simulating Node.js with Java in Javet V8 mode. Why? Because Javet V8 mode is much more secure than the Node.js mode, but lacks of some basic features, e.g. setTimeout, setInterval, etc. So, these must-have API can be found in Javenode.

Feature Javet Javenode
External Dependencies No Yes
Platform Dependent Yes No

If you like my work, please Star this project. And, you may follow me @sjtucaocao, or visit https://blog.caoccao.com/ or http://caoccao.blogspot.com/. And the official support channel is at discord.

Major Features

  • Native Event Loop (vert.x)
  • Same Modules as Node.js
  • Modules
    • console
    • javet
    • timers
    • timers/promises

Quick Start

Dependency

Maven

<dependency>
    <groupId>com.caoccao.javet</groupId>
    <artifactId>javenode</artifactId>
    <version>0.8.0</version>
</dependency>

Gradle Kotlin DSL

implementation("com.caoccao.javet:javenode:0.8.0")

Gradle Groovy DSL

implementation 'com.caoccao.javet:javenode:0.8.0'

Hello Javenode (Static Import)

try (V8Runtime v8Runtime = V8Host.getV8Instance().createV8Runtime();
     JNEventLoop eventLoop = new JNEventLoop(v8Runtime)) {
    eventLoop.loadStaticModules(JNModuleType.Console, JNModuleType.Timers);
    v8Runtime.getExecutor("const a = [];\n" +
            "setTimeout(() => a.push('Hello Javenode'), 10);").executeVoid();
    eventLoop.await();
    v8Runtime.getExecutor("console.log(a[0]);").executeVoid();
}

Hello Javenode (Dynamic Import)

try (V8Runtime v8Runtime = V8Host.getV8Instance().createV8Runtime();
     JNEventLoop eventLoop = new JNEventLoop(v8Runtime)) {
    eventLoop.loadStaticModules(JNModuleType.Console);
    eventLoop.registerDynamicModules(JNModuleType.TimersPromises);
    v8Runtime.getExecutor(
            "import { setTimeout } from 'timers/promises';\n" +
                    "const a = [];\n" +
                    "setTimeout(10, 'Hello Javenode')\n" +
                    "  .then(result => a.push(result));\n" +
                    "globalThis.a = a;").setModule(true).executeVoid();
    eventLoop.await();
    v8Runtime.getExecutor("console.log(a[0]);").executeVoid();
}

TODO

  • To implement fetch
  • To implement fs

License

APACHE LICENSE, VERSION 2.0

Documents

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy