How to connect expo app to localhost server using real device?

46 Views Asked by At

I am developing a mobile app and I encountered an AxiosError when attempting to connect my Expo Go app, running on my physical device, to a server endpoint hosted on localhost:3000. Despite ensuring that my server is up and running, I'm still unable to establish a connection. I am working on physical device not emulator. I tried http://localhost:3000, http://10.0.2.2:3000 also my ip-address but didn't work for me

registering employee
    const register = async (user) => {
        console.log(user)

    try {
        const response = await axios.post(`http://localhost:3000/employees/employee`, user);
        if(response.status === 201){
            console.log('Registration successful:', response.data);
        }
        else if(response.status === 404){
            console.log("can't register please try again later")

        }
        else{
            console.log('something went wrong')
        }
        return response.data; 
    } catch (error) {
         console.error('Error during registration:', error);
        throw error; 
    }
};
0

There are 0 best solutions below