NodeJS (JavaScript / TypeScript)

The following tutorial will show you how to integrate Trustcaptcha into NodeJS .

Preparation

The following preparations should be made before you start implementing Trustcaptcha in your NodeJS backend with JavaScript or TypeScript.

Requirements

  • Basic knowledge in NodeJS , JavaScript and/or TypeScript.
  • Understanding of the basic functionality of Trustcaptcha as well as the backend process.

Knowledge (recommended)

  • Basic knowledge in NodeJS , JavaScript and/or TypeScript.
  • Understanding of the basic functionality of Trustcaptcha as well as the backend process.

Add Dependency

To use the Trustcaptcha library, you must first insert the corresponding dependencies into your project.

NPM

Install the Trustcaptcha library using npm.

Use Library

Below you will find out how you can use the library.

Fetch Result

You can retrieve the verification result using the getVerificationResult() method of the CaptchaManager class from our servers. For this, you must provide your secret-keyue and the verification token.

Use Result

Once you have successfully retrieved the verification result, you can plan your next steps based on it. A concrete overview of all the information contained in the verification result and their respective meanings can be found in The Backend.

Example with Express

The following example shows a possible implementation with the Express library. With a POST request to /api/example, the verification token is transmitted within the request body. Subsequently, the result is retrieved from the server. If the verification has not been passed or the bot score is above 0.5, a warning will be given as an example. Finally, the entire result is returned to the client.
The entire example including source code can be found on Github.