Node.js G-code parser using LinuxCNC rs274ngc interpreter
npm install @linuxcnc-node/gcodeG-code file parser for Node.js using LinuxCNC's rs274ngc interpreter. Parse G-code files and extract sequential operations for toolpath visualization.
``bash`
npm install @linuxcnc-node/gcode
`typescript
import { parseGCode } from "@linuxcnc-node/gcode";
import { OperationType, PositionIndex } from "@linuxcnc-node/types";
const result = await parseGCode("/path/to/program.ngc", {
iniPath: "/path/to/linuxcnc.ini",
onProgress: (p) => console.log(${p.percent}% - ${p.operationCount} ops),
});
console.log(Parsed ${result.operations.length} ops, result.extents);
const { X, Y, Z } = PositionIndex;
for (const op of result.operations) {
if (op.type === OperationType.TRAVERSE) {
console.log(Rapid to ${op.pos[X]}, ${op.pos[Y]}, ${op.pos[Z]});Feed to ${op.pos[X]}, ${op.pos[Y]} @ F${op.feedRate}
} else if (op.type === OperationType.FEED) {
console.log();`
}
}
Returns Promise.
Options (ParseOptions):
- iniPath: Path to LinuxCNC INI file (required)onProgress
- : Callback (progress: ParseProgress) => voidprogressUpdates
- : Target number of progress updates (default: 40, set to 0 to disable)
#### Operation Types
| Type | Description |
| -------------- | --------------------- |
| TRAVERSE | G0 rapid motion |FEED
| | G1 linear feed motion |ARC
| | G2/G3 arc motion |PROBE
| | G38.x probe motion |RIGID_TAP
| | G33.1 rigid tapping |DWELL
| | G4 pause |NURBS_G5/G6
| | NURBS curves |UNITS_CHANGE
| | G20/G21 |PLANE_CHANGE
| | G17/G18/G19 |TOOL_CHANGE
| | M6 |
(See types.ts for full list including offsets and rotations)
- Linux
- LinuxCNC installed (provides rs274ngc interpreter library)
- Node.js 18+
Requires LinuxCNC development headers. Set LINUXCNC_INCLUDE environment variable if headers are not in standard location.
`bash``
export LINUXCNC_INCLUDE=/path/to/linuxcnc/include
npm install
npm run build
GPL-2.0-only