Node.js

Initialize the Project

In this first part of the tutorial, we will build a backend that uses the Vonage Verify API for 2FA. The backend will support both Silent Authentication and SMS-based verification.

Open your terminal and create a new project folder:

The npm init -y command will generate a package.json file with default settings. This file will manage our project's dependencies and scripts.

Now, let's install the required dependencies:

  • express: A lightweight web framework for building APIs.
  • cors: Middleware to allow cross-origin requests (important when connecting with mobile apps).
  • dotenv: To load environment variables from a .env file.
  • @vonage/auth: Manages authentication with Vonage APIs.
  • @vonage/verify2: The Vonage Verify API client to handle 2FA.

After setting up, your folder structure should look like this: