@csound/nodejs package provides Csound for Node.js environments using WebAssembly and WASI.
Installation
Requirements
- Node.js 14 or higher
- WASI support (built into Node.js)
Basic usage
Importing
Initialization
Parameters
withPlugins- Array of WebAssembly plugin libraries to loaduseWorker- Use worker threads (experimental). Default:false
Core API
The Node.js API shares most methods with the browser API. See the Browser API documentation for the complete method reference.Key differences from browser API
- No Web Audio API - Node.js uses different audio backends
- File system - Direct access to the local file system (though virtual filesystem is still available)
- Audio output - Uses the
speakerpackage for audio playback - MIDI - Uses the
easymidipackage for MIDI I/O
File system operations
In Node.js, you can work with both the virtual filesystem and the real filesystem.Virtual filesystem
Real filesystem
When using file paths, Csound can access the real filesystem:Audio output
The Node.js package uses thespeaker package for real-time audio output.
Offline rendering
Render to a WAV file:MIDI support
The Node.js package useseasymidi for MIDI I/O.
Command-line style usage
You can use Csound in a command-line style:Real-time control
Control Csound in real-time using channels:Score events
Send score events dynamically:Table manipulation
Work with function tables:Error handling
Complete example
A complete Node.js application:Event system
The Node.js API supports the same event system as the browser API:Plugins
Load WebAssembly plugins:Performance tips
- Use offline rendering for non-realtime tasks
- Adjust buffer sizes using CSOUND_PARAMS for optimal performance
- Use ksmps appropriately to balance latency and CPU usage
- Minimize channel access in tight loops