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/putty-coreUse Node.js 22.22.2 or newer. Follow language setup for TypeScript tooling and JavaScript module configuration.
Save the fixture
Save sessions.reg at the shown path.
Fixture contents
ini
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions\Demo]
"HostName"="127.0.0.1"
"UserName"="deploy"
"PortNumber"=dword:00000016
"PublicKeyFile"="C:\\keys\\example.ppk"
"TerminalType"="xterm-256color"Read the settings
Save the selected language tab as read-sessions.ts or its matching variant, beside the fixture.
ts
// read-sessions.ts
import {PuttyProfileSource} from '@jalsoedesign/putty-core';
const source = await PuttyProfileSource.fromFile(process.argv[2] ?? './sessions.reg');
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 {PuttyProfileSource} from '@jalsoedesign/putty-core';
const source = await PuttyProfileSource.fromFile(process.argv[2] ?? './sessions.reg');
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 {PuttyProfileSource} from '@jalsoedesign/putty-core';
const source = await PuttyProfileSource.fromFile(process.argv[2] ?? './sessions.reg');
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 {PuttyProfileSource} = await import('@jalsoedesign/putty-core');
const source = await PuttyProfileSource.fromFile(process.argv[2] ?? './sessions.reg');
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
connection: 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.