# node-pathfinding

> a Node.JS implementation for AStar path finding algorithm. This implementation uses primitive data types (Number and Byte/Buffer) to present location and block data that significantly improve the speed and have a good control on memory consumption

Latest version **0.2.6** (published 2013-10-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install node-pathfinding
pnpm add node-pathfinding
yarn add node-pathfinding
bun add node-pathfinding
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.6 |
| Published | 2013-10-01 |
| First published | 2013-05-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.8.0 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9 |
| Author | yi |
| Maintainers | yi |
| Keywords | algorithm, game, astar, grid, movement, multiplayer, pathfinding |

## Links

- npm: https://www.npmjs.com/package/node-pathfinding
- Repository: https://github.com/yi/node-path-finding
- npm.io page: https://npm.io/package/node-pathfinding

## Alternatives

- [@lexical/table](https://npm.io/package/@lexical/table.md) — 3.0M weekly downloads
- [mantine-datatable](https://npm.io/package/mantine-datatable.md) — 98.2K weekly downloads
- [react-native-collapsible-tab-view](https://npm.io/package/react-native-collapsible-tab-view.md) — 70.6K weekly downloads
- [@handsontable/vue3](https://npm.io/package/@handsontable/vue3.md) — 16.1K weekly downloads
- [vuewordcloud](https://npm.io/package/vuewordcloud.md) — 7.2K weekly downloads

## Recent versions

- 0.2.6 (latest) — 2013-10-01
- 0.2.5 — 2013-10-01
- 0.2.3 — 2013-06-12
- 0.2.2 — 2013-05-10
- 0.2.1 — 2013-05-10
- 0.2.0 — 2013-05-09

## README

# Node Path Finding

This is a Node.JS implementation for AStar path finding algorithm.
This implementation uses primitive data types (Number and Byte/Buffer) to present location and block data that significantly improve the speed and have a good control on memory consumption

## Installation

```bash
npm install node-pathfinding
```

## Advantages
- This module uses much less runtime memory then other node path finding module I can find on the net
- The path finding implementation uses primative JavaScript Number type, so much safe to memory leak
- Simple code, easy to change and extend

## Limitations
- The max size of map is limited to 65535 x 65535
- Does not support negtive location

## How To Use

```javascript
var array2d, buf, grid, height, path, pathfinding, width;

pathfinding = require("node-pathfinding");

array2d = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [1, 1, 0, 0], [1, 0, 0, 0]];

width = 4;

height = 5;

// generate grid from 2D array
buf = pathfinding.bytesFrom2DArray(width, height, array2d);
grid = pathfinding.buildGrid(width, height, buf);

path = pathfinding.findPath(1, 0, 1, 4, grid);

console.log("path:" + path);

// print the path
console.log("path on grid :" + (grid.toString(1 << 16 | 0, 1 << 16 | 4, path)));

// output:
// path:65536,131072,131073,196609,196610,196611,196612,131076,65540
// path on grid :[Grid(width=4, height=5)]
// Dump: ░=walkable, ▓=blocked
// ▓S1░
// ░▓23
// ░░▓4
// ▓▓░5
// ▓E76

```

## Glossary
- BrickLoc: To reduce memory usage and use less Object instances, each dot(node, point) in the given map is represented by an 32bit uint, which is composed by ` x << 16 | y `
- Map Buffer: The map is presented by a Buffer, column by row. Each dot(node, point) is a bit in the Buffer. 0 means walkable, 1 means blocked.

## Performance and Memory Consumption

Try ```node tests/sync_astar_continue_test.js```
it does a continuous test of pathfinding on some map fixtures, and the vm memory recycled correctly.

---
_Source: https://npm.io/package/node-pathfinding · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
