An easy to use Node.js wrapper for librespot, an open source Spotify client, based on neon
- Clone this repo
- run
npm install
inside the root folder - Once everything is installed, run
npx neon build
to start building the native module - Build Typescript code with
npm run build
/npm run watch
const { Spotify } = require('../native');
const spotify = new Spotify('<username>', '<password>');
// Load specified track (by id) and starts playing
spotify.play('<track-id>');
setInterval(() => {
console.log('playing? ', spotify.isPlaying());
}, 1000);
const { Spotify } = require('../native');
const spotify = new Spotify('<username>', '<password>');
spotify.getToken('<spotify-client-id>', '<scopes>', (token) => {
console.log(token.getToken(), token.getExpiry(), token.getScope());
});
interface Spotify {
constructor({
username: string,
password: string,
quality?: enum
cacheDir?: string,
connect {
type: enum,
name: string
}
})
play(trackId: string);
stop();
pause();
seek(positionMs: number) throws;
getPosition(): throws number
getTrack(): throws string
isPlaying(): boolean;
emit: started, stopped, loading, playing, paused, endoftrack, volumeset
}
get current volume
interface AccessToken {
getToken(): string;
getExpiry(): number;
getScope(): string[];
}