Implementation:Microsoft Onnxruntime Npm Install Onnxruntime
Appearance
| Field | Value |
|---|---|
| Implementation Name | Npm_Install_Onnxruntime |
| Overview | Installation and configuration of the onnxruntime-node npm package for Node.js inference. |
| Type | External Tool Doc |
| Language | Shell/JavaScript |
| Domains | ML_Inference, JavaScript_Integration |
| Source Repository | microsoft/onnxruntime |
| Last Updated | 2026-02-10 |
Overview
Installation and configuration of the onnxruntime-node npm package for Node.js inference. This implementation covers the npm install command that downloads the package along with platform-specific native ONNX Runtime binaries, and the subsequent import in application code.
API
npm install onnxruntime-node
Then in application code:
const ort = require('onnxruntime-node');
Source Code Reference
- Repository: microsoft/onnxruntime
- Primary Source: js/README.md:L107-139
- Package Directory:
js/node/ - Common API Directory:
js/common/
I/O Contract
| Direction | Name | Type | Description |
|---|---|---|---|
| Input | Node.js project | package.json | A Node.js project with a valid package.json file |
| Input | Node.js runtime | v20+ | Node.js version 20 or higher installed on the system |
| Output | onnxruntime-node | npm package | Installed package in node_modules/ with native ONNX Runtime shared library (.so/.dll/.dylib) |
| Output | onnxruntime-common | npm package | Automatically installed dependency providing the shared TypeScript API surface |
Usage Examples
Basic Installation
# Create a new Node.js project (if needed)
mkdir my-onnx-app && cd my-onnx-app
npm init -y
# Install onnxruntime-node
npm install onnxruntime-node
CommonJS Import
const ort = require('onnxruntime-node');
// The ort object provides access to:
// - ort.InferenceSession (session creation and management)
// - ort.Tensor (tensor construction)
// - ort.env (environment configuration)
Named Import
const { InferenceSession, Tensor } = require('onnxruntime-node');
Verification
const ort = require('onnxruntime-node');
console.log('ONNX Runtime loaded successfully');
// The package will throw an error at require() time if the native
// library cannot be loaded for the current platform.
Key Details
- The package automatically downloads platform-specific native binaries during npm install.
- Supported platforms include Windows (x64), Linux (x64, ARM64), and macOS (x64, ARM64).
- The native shared library is placed in node_modules/onnxruntime-node/bin/napi-v3/.
- The onnxruntime-common dependency is installed automatically and provides shared TypeScript type definitions.
- Node.js v20 or higher is required for N-API compatibility.
Related Pages
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment