The server is a simple Node / Express application. It requires at least Node 14.0.0.
It can be configured using the following variables :
ADDRESS
- The address the server is listening to (default:127.0.0.1
).PORT
- The port the server is listening to (default:8000
).QUOTES_DIR
- Directory in which the quotes are stored (default:quotes
).
The following routes are available :
GET /quotes
- Return the complete list of quotes as a JSON array.POST /quotes
- Create a new quote. This route takes anauthor
field and atext
field in a JSON object.GET /quotes/ws
- Websocket route that broadcasts newly received quotes as JSON objects (see the format below).
Each quote is stored as a separate JSON file under the quotes directory. The following code is an example of a random quote :
{
"id": 3,
"author": "John Doe",
"context": "thinking about life",
"text": "Is the universe a donut?",
"date": 1603371421079
}
The id
field is a unique identifier, the server will start at 1 and auto-increment it when a new quote is received. The date
field is the timestamp at which the quote has been received (elapsed milliseconds since epoch).
You can freely delete or edit any quote file but the server must be restarted for the action to take effect.