$ mkdir spotifyapi (whatever you want)
$ cd spotifyapi
$ npm init -y
$ npm install spotify-web-api-node --save
app.js
const SpotifyWebApi = require('spotify-web-api-node');
// credentials are optional
const spotifyApi = new SpotifyWebApi({
clientId: 'your client id',
clientSecret: 'your client secret id'
});
spotifyApi.setAccessToken('');
// get current play song
spotifyApi.getMyCurrentPlaybackState({})
.then((data) => {
// Output items
// console.log(data.body);
const songId = data.body.item.id;
const songTitle = data.body.item.name;
// song info
console.log(`song id: ${songId}`);
console.log(`song title: ${songTitle}`);
// get audio feature
spotifyApi.getAudioFeaturesForTrack(songId)
.then(function (data) {
console.log(data.body);
}, function (err) {
done(err);
});
}, (err) => {
console.log(`Something went wrong! ${err}`);
});
$ node app.js