Source: spotify-web-api-node
This is a wrapper for the Spotify Web API base on your config for work with spotify api on Node.JS .
A list of selected wrappers for different languages and environments is available at the Developer site's Libraries page.
yarn install
First, you should make a copy from .env.example
and rename to .env.local
with below content:
PORT=5000
SPOTIFY_CLIENT_ID=<YOUR_SPOTIFY_CLIENT_ID>
SPOTIFY_CLIENT_SECRET=<YOUR_SPOTIFY_CLIENT_SECRET>
SPOTIFY_REDIRECT_URI=http://localhost:5000/callback
SPOTIFY_CLIENT_ID and SPOTIFY_CLIENT_SECRET available on spotify dashboard. you should create an app and get them from panel. SPOTIFY_REDIRECT_URI should set on dashboard.
Then, you can run the following command to run server:
node server.js
Spotify's access token, has a expire time (3600 sec), so i wrote a cron in each 1h for refresh the access token.
cron.schedule('0 * * * *', refreshToken);
if you want to run this snippet as service, you should restart after refresh token. you can use pm2 package for run it and then use crontabs on your system and restart service in 1h (after the token was refreshed).