NodeJS express get request is not working on mobile

0 votes

I'm working on a web application. Everything was developed locally, and everything works perfectly. I made the app available on digitalocean. Everything works properly when I access the site from a desktop computer, but express get requests do not work on mobile devices.

This is the app.js code.

const express = require('express');
const app = express();
const fetch = require('node-fetch');
app.listen(3000, () => console.log("Listening at 3000"));
app.use(express.static('public'));
app.use(express.json({limit: '1mb'}));
const hogan = require('hogan.js');
const fs = require('fs');

//GOOGLE PLACES AUTO COMPLETE
app.get('/placesAC/:input', async (request, response) => {
    const userInput = request.params['input'];    
    const placesAPI = 'https://maps.googleapis.com/maps/api/place/autocomplete/json?';
    const placeConditions = '&region=tr';
    const APIKey = '&key=MY_API_KEY';
    const input = 'input=' + userInput;

    const finalURL = placesAPI + input + placeConditions + APIKey;

    const fetch_response = await fetch(finalURL);
    const json = await fetch_response.json();

    response.json(json);

    console.log(userInput);
});

I'm getting it from the client in this manner.

 const inputVal = fromText.value;
    const apiURL = '/placesAC/' + inputVal;
    const response = await fetch(apiURL);
    const json = await response.json();

Jun 7 in Node-js by Vaani
• 7,020 points
88 views

1 answer to this question.

0 votes

For your API call, try to add try-catch to handle the errors,maybe it helps you to debug what's wrong with your code

try {
      const apiURL = '/placesAC/'+ inputVal;
      const response = await fetch(apiURL);
    if (!response.ok) // or check for response.status
        throw new Error(response.statusText);

        const json = await response.json();
} catch (err) {
    console.log(err)
}
answered Jun 7 by Neha
• 8,740 points

Related Questions In Node-js

0 votes
1 answer

How to get GET (query string) variables in Express.js on Node.js?

Hello @kartik, Since you've mentioned Express.js in your ...READ MORE

answered Jul 8, 2020 in Node-js by Niroj
• 82,740 points
1,959 views
0 votes
1 answer

How to get path from the request in nodejs?

Hello @kartik, Try this out: var http = require('http'); var ...READ MORE

answered Oct 14, 2020 in Node-js by Niroj
• 82,740 points
2,359 views
0 votes
1 answer

How to get Node.JS Express to listen only on localhost?

Hello @kartik, This is a bug in hive-go that only ...READ MORE

answered Oct 16, 2020 in Node-js by Niroj
• 82,740 points
3,760 views
0 votes
1 answer
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,009 views
0 votes
1 answer
0 votes
1 answer

Start script missing error when running npm start

It seems that there is an undefined ...READ MORE

answered Feb 10 in Java by Soham
• 8,740 points
2,225 views
0 votes
1 answer

NodeJS express get request is not working on mobile

For your API call, try to add ...READ MORE

answered Jun 9 in Node-js by Neha
• 8,740 points
11 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP