3.3.7 • Published 5 years ago

node-syncthing v3.3.7

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

Build Status npm version

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)
    • 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)

Events

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

5 years ago

3.3.6

5 years ago

3.3.5

5 years ago

3.3.4

6 years ago

3.3.3

8 years ago

3.3.2

8 years ago

3.3.1

8 years ago

3.3.0

8 years ago

3.2.0

8 years ago

3.1.8

8 years ago

3.1.7

8 years ago

3.1.6

8 years ago

3.1.5

8 years ago

3.1.4

8 years ago

3.1.3

8 years ago

3.1.2

8 years ago

3.1.1

8 years ago

3.1.0

8 years ago

3.0.0

8 years ago

2.0.0

8 years ago

1.1.5

9 years ago

1.1.4

9 years ago

1.1.1

9 years ago

1.1.0

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago