Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

103
Views
Express Response not going through

I'm trying to access the Spotify access_token from Postman, but it doesn't seem to be going through. When I try to submit a GET request on Postman for http://localhost:3001/access, I just get "server running". Also, keeping the redirect request in '/login' in mind, when calling a get request from the front end, would I call a request for http://localhost:3001/access or http://localhost:3001/login?

server.js

const app = express();
app.use(cors());
app.set('port', 3001);


app.get('/login', (req, res) => {
  const scope = 'user-read-private user-read-email';
  const state = Math.random().toString(36).slice(2,18);

  const auth_query_parameters = new URLSearchParams({
    response_type: "code",
    client_id: client_id,
    scope: scope,
    redirect_uri: redirect_uri,
    state: state
  });
  
  res.redirect('http://accounts.spotify.com/authorize?' + 
  auth_query_parameters.toString());
});

app.get('/access', (req, res) => {
  const code = req.query.code || null;
  const state = req.query.state || null;
  
  const state_mismatch = new URLSearchParams({
    error: 'state_mismatch'
  });

  if (state == null) {
    res.redirect('/#' + 
    state_mismatch.toString());
  }
  else {
    const authOptions = {
      url: 'https://accounts.spotify.com/api/token',
      form: {
        code: code,
        redirect_uri: redirect_uri,
        grant_type: 'authorization_code'
      },
      headers: {
        'Authorization': 'Basic ' + (Buffer.from(client_id + ':' + client_secret).toString('base64')),
        'Content-Type': "application/x-www-form-urlencoded"
      },
      json: true
    };
    request.post(authOptions, (error, response, body) => {
      if (!error && response.statusCode === 200) {
        const access_token = body.access_token;
        res.send({
          'access_token': access_token
        });
      }
    });
  }
  res.send('hello');
})

app.get('/', (req, res) => {
  res.send('server running');
})

app.listen(3001);
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!