Dijkstra.js is a Rest API that obtains the shortest path between an origin and one or all other nodes of an adjacency table.
Data can be loaded both by uploading a text file or by generating it in a random fashion.
- Node.JS >= v12.18.0
- MongoDB
- Redis
Install all the packages:
npm install
Create an .env
file at the root path of this repository according to the env-example file.
It needs to URI to connect both to Redis and Mongo.
Then run it locally:
npm run dev
It would start listening at port 3333.
The project is ready to use, without authentication in this url.
The documentation for this API can be found here.
An example-file.txt can be found at the root path of this project, which includes the correct format to upload data to the server. It can only support single letters nodes, comma separated, without limit on nodes distance.
The Dijkstra algorithm can be found in the ApiService class, in the line 136 of the dijkstra method.
The project is deployed in this URL.
You can start by loading your data using the example-file.txt file or by calling the generate-data endpoint.
Then, you can use to the shortest-path endpoint to get the shortest path between origin and destination, or you can use the all-paths to get all the shortest paths to/from origin node.
An easy way to upload data to the generate-data
endpoint is to use Postman.
You have to use form-data, select 'File' on the key field and select the file to be uploaded.