Node.js

Set Up the Backend Environment

Create the project

Open a terminal and create a new folder:

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

npm init -y creates a default package.json, which is where npm tracks dependencies and scripts.

Install dependencies

npm install express cors dotenv @vonage/auth @vonage/verify2

What each package is for:

  • express: web framework to build our HTTP API endpoints.
  • cors: allows requests from the Android app (different origin).
  • dotenv: loads environment variables from a local .env file.
  • @vonage/auth: helps generate/authenticate Vonage requests using JWT.
  • @vonage/verify2: the Verify API Server SDK (start a verification, then check a code using the request_id).

Finally, make sure we don’t commit the node_modules folder to our git repository:

echo "node_modules" >> .gitignore

Create app.js

app.js will be the entry point of our backend application. This is the file that starts an HTTP server and exposes endpoints that the mobile app will call.

Create the file:

touch app.js

For now, we’ll add a minimal Express server just to verify everything is wired correctly.

What this does:

  • Loads environment variables using dotenv
  • Creates an Express app
  • Enables:
    • cors so a mobile app can call this API
    • express.json() to read JSON request bodies
  • Exposes a /health endpoint to quickly check that the server is running

You can start the server with:

node app.js

Then open a browser or run:

curl http://localhost:3000/health

You should see:

{ "status": "ok" }

Remember: This endpoint has nothing to do with Verify. It’s just a sanity check before adding more logic.

Create the configuration file

We’ll use a .env file to store configuration and secrets, such as API credentials.

For now, create an empty file:

touch .env

We’ll populate it in the next section, once we introduce the Vonage credentials and explain what each variable is used for.

Finally, make sure .env is not committed so you don’t accidentally commit credentials. Every developer will have their own version:

echo ".env" >> .gitignore

Updated folder structure

After this step, your backend folder will look like: