Skip to content

Rest API to get the shortest path between two nodes using the Dijkstra algorithm

Notifications You must be signed in to change notification settings

matiasbn/dijkstra.js

Repository files navigation

Dijkstra.js

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.

Usage

Prerequisites

  • Node.JS >= v12.18.0
  • MongoDB
  • Redis

Local setup

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.

Heroku deployment

The project is ready to use, without authentication in this url.

Documentation

The documentation for this API can be found here.

example-file.txt

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.

Dijkstra algorithm

The Dijkstra algorithm can be found in the ApiService class, in the line 136 of the dijkstra method.

Example

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.

Uploading data with Postman

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. alt text

About

Rest API to get the shortest path between two nodes using the Dijkstra algorithm

Resources

Stars

Watchers

Forks

Packages

No packages published