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, however 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);
});

and this is how I am fetching it from the client.

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

Jun 8, 2022 in Node-js by Vaani
• 7,020 points
275 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)
}

To know more about Node JS, It's recommended to join Node JS Certification today.

answered Jun 9, 2022 by Neha
• 9,060 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,880 points
2,971 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,880 points
4,031 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,880 points
6,602 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,663 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,215 views
0 votes
1 answer

Start script missing error when running npm start

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

answered Feb 10, 2022 in Java by Soham
• 9,700 points
4,036 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 7, 2022 in Node-js by Neha
• 9,060 points
1,421 views
0 votes
1 answer

What is the role of Nodejs and Express in a MERN stack web application when GraphQL is also used?

Node.js is a JavaScript runtime environment, which ...READ MORE

answered May 27, 2022 in Node-js by Neha
• 9,060 points
2,122 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP