/jexpress

A light express.js like library written in Java (in one file)

Primary LanguageJavaMIT LicenseMIT

jexpress

JExpress.java, a light and slow express.js clone written in Java 17 (in one file). It uses virtual threads if run with Java 21 (or Java 19/20 with --enable-preview).

There is also JExpress8.java, a version backward compatible with Java 8.

The full javadoc

Example

public static void main(String[] args) {
  var app = express();
  app.use(staticFiles(Path.of("public")));

  app.get("/hello/:id", (req, res) -> {
    var id = req.param("id");
    record Hello(String id) {}
    res.json(new Hello(id));
  });
  
  app.get("/LICENSE", (req, res) -> {
    res.sendFile(Path.of("LICENSE"));
  });

  app.listen(3000);
}

Run and test

  • Run the application with

    cd src/main/java
    java JExpress.java
    
  • Test the application with Maven

    mvn clean package