sap-rfc-node
v1.0.1
Published
SAP RFC connector for Node.js using .NET backend - Production ready, zero runtime dependencies, now with vendor update support
Maintainers
Readme
SAP RFC Node.js .NET Bridge
Node.js package for SAP Remote Function Call (RFC) integration using SAP .NET Connector (NCo) 3.0.
Overview
This package bridges Node.js applications with SAP systems through the official SAP .NET Connector. It handles the complexity of .NET interop while providing a straightforward JavaScript API.
Requirements
- Windows (x64 or ARM64)
- .NET Framework 4.8 or higher
- SAP NetWeaver RFC Library (sapnco.dll and sapnco_utils.dll)
- Node.js 14 or higher
Installation
npm install sap-rfc-node-netAfter installation, you must manually add the SAP NCo DLLs:
- Download SAP .NET Connector 3.0 from SAP Support Portal
- Copy
sapnco.dllandsapnco_utils.dllto:node_modules/sap-rfc-node-net/lib/bin/
See SETUP.md for detailed instructions.
Quick Start
const SapRfcClient = require('sap-rfc-node-net');
const client = new SapRfcClient({
host: '192.168.1.100',
client: '400',
sysNr: '00',
user: 'USERNAME',
password: 'PASSWORD',
lang: 'EN'
});
async function main() {
await client.connect();
const result = await client.invoke('RFC_PING');
console.log(result);
await client.close();
}
main();Configuration Options
| Parameter | Required | Default | Description | |-----------|----------|---------|-------------| | host | Yes | - | SAP application server hostname or IP | | client | Yes | - | SAP client number | | sysNr | Yes | - | SAP system number | | user | Yes | - | SAP username | | password | Yes | - | SAP password | | lang | No | EN | Logon language | | poolSize | No | 5 | Connection pool size | | PeakConnectionLimit | No | 10 | Maximum concurrent connections | | connectionIdleTimeout | No | 600 | Idle timeout in seconds |
API Reference
Methods
connect()
Establishes connection to SAP system.
await client.connect();checkDlls()
Verifies that required SAP NCo DLLs are installed.
await client.checkDlls();ping()
Tests the active SAP connection.
await client.ping();invoke(functionName, params)
Executes an RFC function with simple parameters.
const result = await client.invoke('STFC_CONNECTION', {
REQUTEXT: 'Hello SAP'
});invokeFunction(options)
Executes an RFC function with complex parameters including structures and tables.
const result = await client.invokeFunction({
functionName: 'BAPI_VENDOR_FIND',
importParams: {
SEARCHTERM: '0000100*'
},
tables: ['VENDOR_LIST'],
exportParams: ['RETURN']
});close()
Closes the SAP connection.
await client.close();Working with Tables and Structures
Reading Tables
const result = await client.invokeFunction({
functionName: 'BAPI_VENDOR_GETLIST',
importParams: {
MAXROWS: 100
},
tables: ['ADDRESSDATA', 'VENDORLIST']
});
console.log(result.tables.VENDORLIST);Writing Tables
const result = await client.invokeFunction({
functionName: 'BAPI_VENDOR_UPDATE',
importParams: {
VENDOR: '0000100000'
},
importStructures: {
ADDRESS: {
NAME: 'Vendor Name',
CITY: 'New York',
COUNTRY: 'US'
}
},
importTables: {
BANKDATA: [
{
BANK_CTRY: 'US',
BANK_KEY: '123456789',
BANK_ACCT: '9876543210'
}
]
}
});Error Handling
try {
await client.connect();
const result = await client.invoke('BAPI_VENDOR_FIND');
} catch (error) {
if (error.message.includes('Not connected')) {
console.error('Connection error:', error.message);
} else {
console.error('RFC error:', error.message);
}
} finally {
await client.close();
}Connection State Validation
The package validates connection state before executing RFC calls. If you attempt to execute an RFC without connecting first, you will receive a clear error message.
Examples
See the examples/ directory for complete working examples:
basic.js- Simple RFC executiongeneric-rfc.js- Dynamic RFC calls with parametersvendor-data.js- Reading vendor master datavendor-update.js- Updating vendor informationerror-handling.js- Proper error handling patternscheck-setup.js- Verify installation and setup
Architecture
This package uses a CLI-based bridge architecture:
- Node.js spawns a .NET executable (SapRfcBridge.exe)
- Commands and data are exchanged via JSON over stdio
- The .NET bridge handles all SAP NCo operations
- Results are serialized back to Node.js as JSON
This approach provides clean separation and avoids complex native module compilation.
Platform Support
- Windows x64: Full support
- Windows ARM64: Full support
- Linux/macOS: Not supported (requires .NET Framework and SAP NCo for Windows)
For cross-platform deployment, consider running the Windows component in a container. See DOCKER.md for guidance.
Limitations
- Windows only (SAP NCo limitation)
- .NET Framework 4.8 required
- SAP NCo DLLs must be obtained separately from SAP
- Each RFC call spawns a new .NET process (stateless design)
Troubleshooting
DLL Loading Errors
If you see "Could not load file or assembly 'sapnco'":
- Verify DLLs are in
node_modules/sap-rfc-node-net/lib/bin/ - Run
await client.checkDlls()to diagnose - Ensure DLLs match your system architecture (x64 or ARM64)
Connection Errors
If connection fails:
- Verify SAP host is reachable
- Check if VPN connection is required
- Confirm SAP credentials are correct
- Verify firewall allows SAP RFC port (default 33XX where XX is system number)
Not Connected Errors
If you see "Not connected to SAP":
- Call
await client.connect()before executing RFCs - Connection is lost after
client.close()- reconnect if needed - Check network stability for long-running operations
License
MIT
Support
For SAP .NET Connector documentation and downloads, visit SAP Support Portal.
For package issues, see the GitHub repository.
