Node.js demo reference
The Node.js demo source is on GitHub.
fly launch will provide a Dockerfile
and a fly.toml config file. When you make changes to your application, you can run npx @flydotio/dockerfile to produce updated Dockerfiles.
How the pieces are put together:
- The original web-dictaphone app (minus the HTML) is in the public directory, and contains icons, scripts, styles, and a web manifest; all served as static files.
views/index.ejscontains the HTML template.- app.js contains the server implementation, based on Express.js. There are lots of JavaScript frameworks out there, this is perhaps the oldest and most minimalist.
- The pg module is used to access PostgreSQL.
Access to the database is through the
DATABASE_URLsecret. This module is low level which is sufficient for this demo, but most modern Node.js applications use an ORM. - The AWS SDK for JavaScript
is used to access Tigris. The following secrets are used to
establish the connection:
AWS_ACCESS_KEY_ID,AWS_ENDPOINT_URL_S3,AWS_REGION,AWS_SECRET_ACCESS_KEY, andBUCKET_NAME. - The express-ws module is used for WebSocket support.
- The redis module
is used to access Redis. The
REDIS_URLsecret is used to access the database.
Key points of logic:
public/scripts/app.jshas been modified to make server requests at various points using the Fetch API.app.jscontains the logic to build responses to requests for the index page, and to GET, PUT, and DELETE audio clips.pubsub.jscontains the logic to subscribe to adictaphone:timestampredis queue, and to forward updates to all open websocket connections.websocket.jscontains the client implementation of web sockets. When update notifications are received, the index page is re-retrieved and the body of the DOM is replaced with new contents.- When the
WHISPER_URLsecret is set,PUTrequests will cause the audio clips to be passed to the Whisper server, and responses will be used to update the PostgreSQL database. The code for this is in app.js.