mpdclient.js
v0.0.21
Published
Yet another MPD client for NodeJS. Provides Promise-based API for interraction with MPD server.
Readme
mpdclient.js 
Upcoming Promise-based MPD client for NodeJS.
Init
$ npm iAlternate variant via yarn:
$ yarn installBuild
$ npm run buildUsage
Import module:
// Import MPDClient.js module.
const mpdclient = require('mpdclient.js');Create connection with MPD server:
// Create connection with MPD server.
const client = new mpdclient.MPDClient('localhost', 6600);Prepare command (or command list) for execute:
// Create command.
const command = new mpdclient.MPDCommand('status');// Or you can create chain of commands.
const commands = [
new mpdclient.MPDCommand('play'),
new mpdclient.MPDCommand('status')
];
// You can pass the mode for eval command list.
const commandList = new mpdclient.MPDCommandList(commands, mpdclient.MPDCommandList.COMMAND_LIST_OK_BEGIN);Execute command or command list:
// As MPDClient.js provides Promise-based API it means
// that there are 2 callbacks for handle execution result:
client.execute(command).then(
response => {
// Handle parsed response object.
},
error => {
// Handle error.
}
);Completed example
const mpdclient = require('mpdclient.js');
const client = new mpdclient.MPDClient('localhost', 6600);
const command = new mpdclient.MPDCommand('status');
client.execute(command)
.then(response => console.log(response))
.catch(error => console.log(error));