Skip to content

Beacon backend

The beacon backend is used to store information about each beacon that is retrieved using the beacon ID. This is mocking the api that stephear uses but it has only the basic functionality that we need to test our application with the beacons. For each beacon the database can store the following information:

  • Beacon Identifier
  • Short description
  • Long description
  • TX power
  • Latitude
  • Longtitude

It is necessary that we store this information on the api because the beacon can only tansmit an ID. Aditionally this allows us to modify information related to the beacon without needed to physically access it(most beacons are not connected to the internet).

Setup

Ensure that the latest version of node.js is installed on your system.

Using the terminal navigate to /api and run npm install. This will install all the dependencies of the project.

Run the npm run start to transpile the typescript into javascript and start a local server. The server will be available on localhost port 3000.

Adding and removing beacons

Beacons can be created or removed using interface of the beacon web application or using the endpoints on the api. For more details see either the api reference or the frontend documentation.

Technical specs

The api is built with express framework of node.js. Typescript was used to make the code more robust and easier to extend.

For the data layer Prisma ORM is used so that we can clearly define and extend the data model and avoid writing our own sql queries. Typescript was combined well with prisma to provide type completion and make it easier to work with the data model.

During testing prisma is configured with sqlite that removes the need for a database server during development but a migration to a more scalable solution, although unlikely to happen, can be done with a single command.


Last update: June 2, 2023