DEV Community

Cover image for ExpressWebJs 4 is now released!
Chukwuemeka Igbokwe
Chukwuemeka Igbokwe

Posted on

ExpressWebJs 4 is now released!

ExpressWebJs version 4 is now released and it includes many new features, including:

  • Mongoose and ObjectionJs ORM support.
  • SQL database relationship addons.
  • Multi-tenancy support for mongo DB.
  • Route match.
  • Route redirect.
  • Improved middleware handler methods.
  • Improved service registry handlers.
  • Custom validation rules.
  • Improved event class generation.
  • Added Redis to the supported queue connections.
  • Service communication for distributed services.
  • Domain-driven design (DDD).
  • Support for Restana platform service for faster request processing.
  • New utility features like Optional( ),ObjectMapper( ), FirstCharacterToLowerCase( ), Group( ), ObjectHasProperty( ).
  • New Collection feature which helps you work on advanced data structures and algorithms.

ExpressWebJs uses a variety of community driven packages for a number of features in the framework.

ExpressWebJs version 4 will receive bug fixes until November 2023 and security fixes until February 2024. Here are some of the features that we’ve covered in detail.

We’ve added some relationship add-ons for the SQL database model.
The relationship mapping method now has a nice way of handling relationships with the new hasMany, belongsTo, hasOne, hasOneThrough, hasManyThrough methods that also accept additional options.

hasManyThrough()

 export class UserModel extends Model {
  static tableName = "users";

  id!: string;
  name!: string;
  email!: string;
  password!: string;

  static relationMappings() {
    return {
      carOwner: this.hasManyThrough("App/Model/Cars_model",
      "App/Model/CarOwners_model", {
        join_final_foreign_key: "user_id",
        join_parent_foreign_key: "car_id",
      }),
    };
  }
}
Enter fullscreen mode Exit fullscreen mode

hasOneThrough()

 export class UserModel extends Model {
  static tableName = "users";

  id!: string;
  name!: string;
  email!: string;
  password!: string;

  static relationMappings() {
    return {
      carOwner: this.hasOneThrough("App/Model/Cars_model", 
        "App/Model/CarOwners_model", {
        join_final_foreign_key: "user_id",
        join_parent_foreign_key: "car_id",
      }),
    };
  }
}
Enter fullscreen mode Exit fullscreen mode

hasOne()

export class UserModel extends Model {
  static tableName = "users";

  id!: string;
  first_name!: string;
  last_name!: string;
  email!: string;
  password!: string;

  static relationMappings() {
    return {
      profile: this.hasOne("App/Model/Profile_model"),
    };
  }
}
Enter fullscreen mode Exit fullscreen mode

hasMany()

export class UserModel extends Model {
  static tableName = "users";

  id!: string;
  first_name!: string;
  last_name!: string;
  email!: string;
  password!: string;

  static relationMappings() {
    return {
      profile: this.hasMany("App/Model/Cars_model"),
    };
  }
}
Enter fullscreen mode Exit fullscreen mode

belongsTo()

export class Posts extends Model {
  static tableName = "posts";

  id!: string;
  name!: string;
  user_id!: string;

  static relationMappings() {
    return {
      users: this.belongsTo("App/Model/Users_model"),
    };
  }
}
Enter fullscreen mode Exit fullscreen mode

Relation filters
You can also add some filters to your relationship mapping:

static relationMappings() {
    return {
      profile: this.hasMany("App/Model/Cars_model",{
        filter: (builder) => {
          builder.where("name", "Mercedes");
        },
      }),
    };
  }
Enter fullscreen mode Exit fullscreen mode

Some route features are also added

Route Match
Sometimes you may need to register a route that responds to multiple HTTP verbs. You may do so using the match method. Or, you may even register a route that responds to all HTTP verbs using the all method:

  Route.match(["get", "post"], "/books", 
        "UserController@process");
Enter fullscreen mode Exit fullscreen mode

Route Redirect
If you are defining a route that redirects to another URI, you may use the Route redirect method. This method provides a convenient shortcut so that you do not have to define a full route or controller for performing this task.

 Route.redirect("source_url", "destination_url");
Enter fullscreen mode Exit fullscreen mode

You can see the complete list of new features and updates on ExpressWebJs website.

Kindly follow ExpressWebJs on twitter.

And don't forget to star on github.

You can also join the discord channel

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay