Installing Dependencies
Install npm packages
express- Web frameworkexpress-ws- WebSocket supportcors- Cross-origin resource sharingdotenv- Environment variable managementtwilio- Twilio SDK for phone callsopenai- OpenAI SDK for Realtime APIwinston- Logging framework@supabase/supabase-js- Supabase client
Configure environment variables
Create a
.env file in the backend directory. See Environment Variables for required variables.Directory Structure
The backend follows a modular structure:Key Files
index.js - Server initialization- Sets up Express app
- Configures CORS
- Registers routes and WebSocket handlers
- Starts server on configured port
- Loads environment variables
- Exports configuration constants
- Defines system messages and voice settings
/- Health check endpoint/call-customer- Initiates Twilio calls- Handles Supabase database operations
- Manages media stream connections
- Bridges Twilio and OpenAI Realtime API
- Handles audio streaming
Starting the Server
Port Configuration
The server port is configured via thePORT environment variable:
.env
When deploying, ensure your hosting platform’s port configuration matches your environment variable.
CORS Setup
The backend is configured with CORS to allow frontend connections:index.js
Logging Configuration
Highway uses Winston for structured logging. The logger is configured inlogging/logger.js:
Features:
- Console output with colorization
- Timestamp formatting (YYYY-MM-DD HH:mm:ss)
- Exception handling
- Info level logging by default
info- General information (default)warn- Warning messageserror- Error messagesdebug- Debug information
response.content.donerate_limits.updatedresponse.doneinput_audio_buffer.committedinput_audio_buffer.speech_stoppedinput_audio_buffer.speech_startedsession.created
Verification
Test your backend setup:Verify environment variables
Check that all required variables are loaded by reviewing the startup logs.
Next Steps
Environment Variables
Configure all required environment variables
Frontend Setup
Set up the Next.js frontend