Skip to content
 
 

Repository files navigation

Google OR-Tools for JavaScript

Build schedules, optimize delivery routes, and solve assignment and packing problems in TypeScript or JavaScript. Run Google OR-Tools in the browser with multithreaded WebAssembly, in Node.js, or on a native server through the same API.

GitHub npm

Standalone packages: npm: cp-sat-wasm npm: routing-wasm

Package Native Server Vite 8 dev Chromium Vite 8 dev Firefox Vite 8 dev WebKit Vite 8 static Chromium Vite 8 static Firefox Vite 8 static WebKit Webpack 5 dev Chromium Webpack 5 dev Firefox Webpack 5 dev WebKit Webpack 5 static Chromium Webpack 5 static Firefox Webpack 5 static WebKit Rollup 4 static Chromium Rollup 4 static Firefox Rollup 4 static WebKit Node 24 Node 26.13.1 Deno 2.9.7 Bun 1.4.4

Install:

npm install or-tools-wasm

Documentation · Try the examples · Used in PragmaPlanner.

Same API. Fast solves on any device.

Sign up for the hosted cloud version.

  • Scheduling and routing: build employee rosters, shift schedules, school timetables, production plans, and delivery route planners. Solve traveling salesman (TSP) and vehicle routing (VRP) problems.
  • Optimization solvers: Google OR-Tools for constraint programming, linear programming (LP), mixed-integer programming (MIP), assignment, bin packing, resource allocation, knapsack, and network flow.
  • TypeScript and JavaScript: build models with typed variables and constraints, then read solutions through a consistent API.
  • Browser and server: run multithreaded WebAssembly in the browser, use Node.js, Deno, or Bun, or send the same model to a native server.

Examples

Click an image to try it.

CP-SAT calendar scheduling with task dependencies and employee availability CP-SAT warehouse logistics optimization with pallet placement and shelf weight limits

Factory floor optimization Sudoku solver

Network design optimization Vehicle routing optimization Steel mill slab optimization

Install

npm install or-tools-wasm

Only need one solver? Install CP-SAT or Routing as a smaller standalone package.

npm install cp-sat-wasm
# Or:
npm install routing-wasm

For browser headers and bundler configuration, see Setup.

Solve your first problem

A workshop has 12 hours available. A desk takes 3 hours and earns 20. A table takes 4 hours and earns 30. What should it make to maximize profit?

import { CpModel, CpSat } from 'or-tools-wasm/cp-sat';

const model = new CpModel();
const desks = model.newIntVar(0, 4, 'desks');
const tables = model.newIntVar(0, 3, 'tables');

model.addLinearConstraint(desks.times(3).plus(tables.times(4)), 0, 12);
model.maximize(desks.times(20).plus(tables.times(30)));

const result = await CpSat.solve(model, { numWorkers: 1 });

if (result.hasSolution) {
  console.log({
    desks: result.value(desks),
    tables: result.value(tables),
    profit: result.objectiveValue,
  });
}

The optimal plan is 3 tables, no desks, and a profit of 90.

Browser solves use a worker by default to keep the page responsive. In Node.js, direct execution can block the event loop, delaying timers and timer-driven cancellation. Use executor: 'worker' for responsive applications and cancellation from timers. Execution options cover direct, worker, and server execution, progress events, and cancellation.

Explore the API documentation

Supported solvers

Supported Solver What it does
✅ CP-SAT Constraint and integer optimization for Boolean, integer, scheduling, and logical models.
✅ Routing Vehicle routing (VRP), TSP, pickup-delivery, time windows, breaks, resource groups, state-dependent transit, and route reoptimization.
✅ MPSolver Linear and mixed-integer programming with selectable backends, incremental sessions, native MIP callbacks, and solution pools where supported.
✅ MathOpt Linear, quadratic, and multi-objective models, incremental solving, and native callbacks. Capabilities depend on the selected backend.
✅ GLOP Google's simplex linear programming solver.
✅ PDLP First-order LP and convex diagonal quadratic solving, with native model import and iteration statistics.
✅ SAT integer programming CP-SAT-backed integer programming backend for pure integer linear models.
✅ CLP COIN-OR linear programming backend.
✅ GLPK GNU linear and mixed-integer programming backend.
✅ SCIP / GSCIP SCIP-based mixed-integer optimization through MPSolver and MathOpt.
✅ CBC COIN-OR branch-and-cut mixed-integer programming backend.
✅ BOP Boolean/integer optimization backend through MPSolver.
✅ Knapsack Dedicated 0-1 and multi-dimensional knapsack solver, plus the MPSolver Knapsack backend.
✅ Network flow Dedicated max-flow, min-cost-flow, and linear-sum assignment algorithms.
✅ Assignment Linear-sum assignment through the dedicated Network Flow API.
✅ Set Cover Weighted set covering with construction and local-search heuristics, MIP and LP methods, and Lagrangian bounds.
✅ RCPSP Resource-constrained scheduling through CP-SAT, including multimode, RCPSP/Max, consumer-producer, and resource-investment models.

Compatibility

Supported Runtime
✅ Chromium browsers
✅ Firefox
✅ Playwright WebKit
✅ Node.js
✅ Deno
✅ Bun
✅ Native C++ solver server

Local WebAssembly includes JSPI and Asyncify runtimes, with automatic selection for the current environment. Only the selected runtime is loaded.

WebKit coverage uses Playwright’s browser build, not released Safari or iOS Safari. WebKit 27.2 can reject cached worker reloads after startup cancellation; our Vite test and example servers use Cache-Control: no-store to avoid this.

Tested bundlers: Vite, Webpack, and Rollup.

See testing for the fixture matrix and benchmarks for performance measurements.

About

Built on Google OR-Tools. Maintained by Axel Wickman. Licensed under Apache 2.0.