Node.JS – Foal framework version 4.5 is released 🎉

Version 4.5 of Foal, a full-featured Node.JS framework for building web applications, is out!

Here’s what’s inside.

Asynchronous tasks

In some situations, we need to execute a specific task without waiting for it and without blocking the r…


This content originally appeared on DEV Community and was authored by Loïc Poullain

Version 4.5 of Foal, a full-featured Node.JS framework for building web applications, is out!

Here's what's inside.

Asynchronous tasks

In some situations, we need to execute a specific task without waiting for it and without blocking the request.

This could be, for example, sending a specific message to the CRM or company chat. In this case, the user needs to be able to see his or her request completed as quickly as possible, even if the request to the CRM takes some time or fails.

To this end, Foal version 4.5 provides an AsyncService to execute these tasks asynchronously, and correctly catch and log their errors where appropriate.

import { AsyncService, dependency } from '@foal/core';

import { CRMService } from './somewhere';

export class SubscriptionService {
  @dependency
  asyncService: AsyncService;

  @dependency
  crmService: CRMService;

  async subscribe(userId: number): Promise<void> {
    // Do something

    this.asyncService.run(() => this.crmService.updateUser(userId));
  }
}

Social authentication for SPAs

If you wish to manually manage the redirection to the consent page on the client side (which is often necessary when developing an SPA), you can now do so with the createHttpResponseWithConsentPageUrl method. It returns an HttpResponseOK whose body contains the URL of the consent page.

export class AuthController {
  @dependency
  google: GoogleProvider;

  @Get('/signin/google')
  getConsentPageURL() {
    return this.google.createHttpResponseWithConsentPageUrl();
  }

  // ...

}

Google social authentification

The typing of the GoogleProvider service has been improved. The userInfo property returned by getUserInfo is now typed with the values returned by the Google server.

const { userInfo } = await this.googleProvider.getUserInfo(...);

// userInfo.email, userInfo.family_name, etc

Logging improvements

In previous versions, the util function displayServerURL and configuration errors printed logs on several lines, which was not appropriate for logging software.

From version 4.5 onwards, configuration errors are displayed on a single line and the displayServerURL function is marked as deprecated.

CLI fixes

When running npx foal connect react to connect the React application to the Foal application in development, the following features did not work:

  • Proxify requests from the client to the server without needing to enable CORS or specify a different port in development.
  • Build the client application in the server application's public directory.

This is fixed in v4.5.

Global use of CLI deprecated

In previous versions, the tutorial suggested installing the CLI globally to create a new application or generate files. However, it is considered bad practice to install a dependency globally for local use.

In addition, the CLI was also installed locally so that the build command would work when deploying the application to a CI or to production. This was maintaining two versions of the CLI.

To correct this, in the documentation and examples, the CLI is now always installed and used locally. To use it, simply add npx before each command (except for createapp).

# Before
foal createapp my-app

foal generate script foobar
foal createsecret

# After
npx @foal/cli createapp my-app

npx foal generate script foobar
npx foal createsecret

This post was originally published on Foal's blog.


This content originally appeared on DEV Community and was authored by Loïc Poullain


Print Share Comment Cite Upload Translate Updates
APA

Loïc Poullain | Sciencx (2024-08-24T17:47:17+00:00) Node.JS – Foal framework version 4.5 is released 🎉. Retrieved from https://www.scien.cx/2024/08/24/node-js-foal-framework-version-4-5-is-released-%f0%9f%8e%89/

MLA
" » Node.JS – Foal framework version 4.5 is released 🎉." Loïc Poullain | Sciencx - Saturday August 24, 2024, https://www.scien.cx/2024/08/24/node-js-foal-framework-version-4-5-is-released-%f0%9f%8e%89/
HARVARD
Loïc Poullain | Sciencx Saturday August 24, 2024 » Node.JS – Foal framework version 4.5 is released 🎉., viewed ,<https://www.scien.cx/2024/08/24/node-js-foal-framework-version-4-5-is-released-%f0%9f%8e%89/>
VANCOUVER
Loïc Poullain | Sciencx - » Node.JS – Foal framework version 4.5 is released 🎉. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/08/24/node-js-foal-framework-version-4-5-is-released-%f0%9f%8e%89/
CHICAGO
" » Node.JS – Foal framework version 4.5 is released 🎉." Loïc Poullain | Sciencx - Accessed . https://www.scien.cx/2024/08/24/node-js-foal-framework-version-4-5-is-released-%f0%9f%8e%89/
IEEE
" » Node.JS – Foal framework version 4.5 is released 🎉." Loïc Poullain | Sciencx [Online]. Available: https://www.scien.cx/2024/08/24/node-js-foal-framework-version-4-5-is-released-%f0%9f%8e%89/. [Accessed: ]
rf:citation
» Node.JS – Foal framework version 4.5 is released 🎉 | Loïc Poullain | Sciencx | https://www.scien.cx/2024/08/24/node-js-foal-framework-version-4-5-is-released-%f0%9f%8e%89/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.