3.3.7 • Published 6 years ago
node-syncthing v3.3.7
Install:
npm i node-syncthing --save
Usage:
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))
Methods
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)
- 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)
Events
- 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
Example:
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')
Dev
Build
npm i
npm run build
Test
cd test
syncthing -home . -no-browser
In new terminal window:
npm test
3.3.7
6 years ago
3.3.6
6 years ago
3.3.5
7 years ago
3.3.4
7 years ago
3.3.3
9 years ago
3.3.2
9 years ago
3.3.1
9 years ago
3.3.0
9 years ago
3.2.0
9 years ago
3.1.8
9 years ago
3.1.7
9 years ago
3.1.6
9 years ago
3.1.5
9 years ago
3.1.4
9 years ago
3.1.3
10 years ago
3.1.2
10 years ago
3.1.1
10 years ago
3.1.0
10 years ago
3.0.0
10 years ago
2.0.0
10 years ago
1.1.5
10 years ago
1.1.4
10 years ago
1.1.1
10 years ago
1.1.0
10 years ago
1.0.1
10 years ago
1.0.0
10 years ago