Set Up the Backend Environment
Create the project
Open a terminal and create a new folder:
npm init -y creates a default package.json, which is where npm tracks dependencies and scripts.
Install dependencies
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:
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:
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:
corsso a mobile app can call this APIexpress.json()to read JSON request bodies
- Exposes a
/healthendpoint to quickly check that the server is running
You can start the server with:
Then open a browser or run:
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:
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:
Updated folder structure
After this step, your backend folder will look like:
Getting Started with Silent Authentication
Silent Authentication takes quite a bit to understand. This tutorial shows you how to build an integration from scratch with Nodejs and Kotlin