text: let express = require('express')
  let request = require('request')
  let querystring = require('querystring')
  
  var client_id = "5737379c912a4127bd009ea65f0fa760"; // Your client id
  var client_secret = "e14ce407075e4dc4b032d54d4178a108"; // Your secret
  
  let app = express()
  
  let redirect_uri = 
    process.env.REDIRECT_URI || 
    'http://localhost:8888/callback'
  
  app.get('/login', function(req, res) {
    res.redirect('https://accounts.spotify.com/authorize?' +
      querystring.stringify({
        response_type: 'code',
        client_id: client_id,
        scope: 'user-read-private user-read-email playlist-read-private playlist-read-collaborative user-read-playback-state',
        redirect_uri
      }))
  })
  
  app.get('/callback', function(req, res) {
    let code = req.query.code || null
    let authOptions = {
      url: 'https://accounts.spotify.com/api/token',
      form: {
        code: code,
        redirect_uri,
        grant_type: 'authorization_code'
      },
      headers: {
        'Authorization': 'Basic ' + (new Buffer(
          client_id + ':' + client_secret
        ).toString('base64'))
  
      },
      json: true
    }
    request.post(authOptions, function(error, response, body) {
      var access_token = body.access_token
      let uri = process.env.FRONTEND_URI || 'http://localhost:3000'
      res.redirect(uri + '?access_token=' + access_token)
    })
  })
  
  let port = process.env.PORT || 8888
  console.log(`Listening on port ${port}. Go /login to initiate authentication flow.`)
  app.listen(port)
  
  