npm i node-syncthing --save
const syncthing = require('node-syncthing')
//Create an instance
const st = syncthing(options)
Options: object
- host:
string
(default:127.0.0.1
) - port:
number
(default:8384
) - apiKey:
string
(not necessary if username and password are provided) - https:
boolean
(defaults: true) - username:
string
- password:
string
- eventListener:
boolean
(default:false
) - retries:
number
(default:0
, how many times to try after connection loss for event listener) - events:
string
(event types to filter, leave empty to catch the default event types (default))
Using callbacks:
syncthing.endpoint.method(options, callback);
Using promises:
syncthing.endpoint.method(options).then(responseHandler).catch(errorHandler);
Information about options: Syncthing API
Endpoints: endpoint/method (options)
- System (system)
- ping
- shutdown
- restart
- version
- status
- connections
- getConfig
- setConfig (config)
- configInSync
- debug
- getDiscovery
- setDiscovery (device, address)
- errors
- clearErrors
- logs
- getUpgrade
- setUpgrade
- pause (device)
- resume (device)
- Database (db)
- scan (folder, [subdir])
- status (folder)
- browse (folder, levels, [subdir])
- completion (device, folder)
- file (folder, file)
- getIgnores (folder)
- setIgnores (folder, [ignores])
- need (folder)
- prio (folder, file)
- override (folder)
- revert (folder)
- Statistics (stats)
- devices
- folders
- Misc (misc)
- folders (device)
- lang
- report
Data and errors can be handled with callbacks or with promises:
- Promises (Provide no callback function)
- Callback (Provide a callback function as the last argument in the method)
- Error argument (returns the error or null if there was none)
- Data argument (api response)
- error (Emmitted on event listener error)
- configSaved
- deviceConnected
- deviceDisconnected
- deviceDiscovered
- deviceRejected
- downloadProgress
- folderCompletion
- folderErrors
- folderRejected
- folderSummary
- itemFinished
- itemStarted
- localIndexUpdated
- ping
- remoteIndexUpdated
- starting
- startupComplete
- stateChanged
- More event types in the docs
const syncthing = require('node-syncthing')
//Options
const options = {
host: 'localhost',
port: 8384,
apiKey: 'Tj2pqyhhkNFs43r5vQsMgLtwvT94Ah4F',
eventListener: true,
retries: 10,
}
const st = syncthing(options)
//With Callback
st.system.ping((err, res) => {
if (!err) {
console.log(res.ping) //pong
}else {
console.error(err)
}
})
//With Promises
st.system.ping().then((res) => {
console.log(res.ping) //pong
}).catch((err) => {
console.error(err)
})
//Listen to events
st.on('ping', () => {
console.log('pong')
})
st.on('error', (err) => {
console.error(err)
})
//Removing event listeners will stop the event polling
st.removeAllListeners('ping')
st.removeAllListeners('error')
npm i
npm run build
cd test
syncthing -home . -no-browser
In new terminal window:
npm test