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:

mkdir -p vonage-verify-tutorial/backend
cd vonage-verify-tutorial/backend
npm init -y

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:

npm install express dotenv cors @vonage/verify2 @vonage/auth --save
  • 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:

backend/
├── server.js         # Main server file
├── .env              # Environment variables
└── package.json      # Project configuration