API quick start
Read saved sessions, select one by exact path and search connection metadata. This example uses synthetic settings on the host and does not connect to a server.
Install
sh
npm install @jalsoedesign/heidisql-coreUse Node.js 22.22.2 or newer. Follow language setup for TypeScript tooling and JavaScript module configuration.
Save the fixture
Save portable_settings.txt at the shown path.
Fixture contents
text
Servers\Demo\Host 1 127.0.0.1
Servers\Demo\User 1 analyst
Servers\Demo\NetType 3 2
Servers\Demo\SSHtunnelHost 1 127.0.0.1
Servers\Demo\SSHtunnelUser 1 deploy
Servers\Demo\SSHtunnelPrivateKey 1 C:\keys\example.ppkDownload the file to preserve the actual tab delimiters.
Read the settings
Save the selected language tab as read-sessions.ts or its matching variant, beside the fixture.
ts
// read-sessions.ts
import {HeidiSqlProfileSource} from '@jalsoedesign/heidisql-core';
const source = await HeidiSqlProfileSource.fromFile(process.argv[2] ?? './portable_settings.txt');
const profiles = source.list();
const selected = source.get('Demo');
if (!selected) {
throw new Error('The demo profile is missing');
}
console.log('Profiles: ' + profiles.length);
console.log('Selected: ' + selected.path);
for (const connection of selected.connections) {
console.log(connection.id + ': ' + connection.protocol + ' ' + connection.endpoint.host + ':' + connection.endpoint.port);
}
console.log('Host matches: ' + source.search('127.0.0.1', {fields: 'all'}).length);
console.log('Metadata only: no server connection.');js
// read-sessions.js
import {HeidiSqlProfileSource} from '@jalsoedesign/heidisql-core';
const source = await HeidiSqlProfileSource.fromFile(process.argv[2] ?? './portable_settings.txt');
const profiles = source.list();
const selected = source.get('Demo');
if (!selected) {
throw new Error('The demo profile is missing');
}
console.log('Profiles: ' + profiles.length);
console.log('Selected: ' + selected.path);
for (const connection of selected.connections) {
console.log(connection.id + ': ' + connection.protocol + ' ' + connection.endpoint.host + ':' + connection.endpoint.port);
}
console.log('Host matches: ' + source.search('127.0.0.1', {fields: 'all'}).length);
console.log('Metadata only: no server connection.');js
// read-sessions.mjs
import {HeidiSqlProfileSource} from '@jalsoedesign/heidisql-core';
const source = await HeidiSqlProfileSource.fromFile(process.argv[2] ?? './portable_settings.txt');
const profiles = source.list();
const selected = source.get('Demo');
if (!selected) {
throw new Error('The demo profile is missing');
}
console.log('Profiles: ' + profiles.length);
console.log('Selected: ' + selected.path);
for (const connection of selected.connections) {
console.log(connection.id + ': ' + connection.protocol + ' ' + connection.endpoint.host + ':' + connection.endpoint.port);
}
console.log('Host matches: ' + source.search('127.0.0.1', {fields: 'all'}).length);
console.log('Metadata only: no server connection.');js
// read-sessions.cjs
async function main() {
const {HeidiSqlProfileSource} = await import('@jalsoedesign/heidisql-core');
const source = await HeidiSqlProfileSource.fromFile(process.argv[2] ?? './portable_settings.txt');
const profiles = source.list();
const selected = source.get('Demo');
if (!selected) {
throw new Error('The demo profile is missing');
}
console.log('Profiles: ' + profiles.length);
console.log('Selected: ' + selected.path);
for (const connection of selected.connections) {
console.log(connection.id + ': ' + connection.protocol + ' ' + connection.endpoint.host + ':' + connection.endpoint.port);
}
console.log('Host matches: ' + source.search('127.0.0.1', {fields: 'all'}).length);
console.log('Metadata only: no server connection.');
}
main().catch(error => {
console.error(error);
process.exitCode = 1;
});Run it
sh
npx tsx read-sessions.tssh
node read-sessions.jssh
node read-sessions.mjssh
node read-sessions.cjsOutput
text
Profiles: 1
Selected: Demo
database: mysql 127.0.0.1:3306
ssh: ssh 127.0.0.1:22
Host matches: 1
Metadata only: no server connection.Download: TypeScript · JavaScript · MJS · CommonJS
Continue by task
Continue with profile queries, storage and discovery, or previewing a change. Validation, unsupported settings and source lifetimes are explained in the corresponding guides and API reference.