Very simple Node.js API for autocompleting addresses built with Express + TypeScript.
Currently hosted on my Oracle Cloud ARM VM instance: https://autocomplete-addresses-api.nunogois.com
Uses autocomplete-addresses as the front-end.
Since I prefer a microservice and decoupled approached compared to setting up monorepos, as always I decided to separate the front-end and back-end in different repos. Who knows, maybe this API will be consumed by other front-end apps in the future, so it should live independently.
flowchart LR
A[Front-end\nautocomplete-addresses] -- Search Query --> B[Back-end\nautocomplete-addresses-api]
B -- Addresses, max 20 --> A
- Clone the repo:
git clone https://github.com/nunogois/autocomplete-addresses-api.git
; - cd into the folder:
cd autocomplete-addresses-api
; - Install dependencies:
yarn
ornpm install
; - Run tests:
yarn test
ornpm run test
; - Run the server:
yarn start
ornpm run start
;
Even though I wanted to use something like trie-search for the autocomplete functionality, it seems it does not support TypeScript currently. Because of that, I decided to implement my own approach in an OOP-like manner with searchable.ts
. It's totally in-memory after reading the JSON file, so it should also be pretty fast with a similar functionality.
I considered the tests included in the tests
folder for router.ts
and searchable.ts
to represent a good enough code coverage given the time available.
Also added some comments to the code, even though most are redundant, since the code is pretty self-explanatory.