我想在本地 Android 设备上运行 React Native 应用程序。该应用程序使用 Node js API 从 mysql 获取数据。问题是,我的 Android 设备无法访问 Node js 应用程序,导致没有数据。该应用程序在使用地址 10.0.2.2 的 Android 模拟器上运行良好,但无法在 Android 设备上访问此地址 P.S Node js API 位于本地服务器 (localhost:3000)
最佳答案
所以我就这样解决了。 1. 我使用 ipconfig 从 cmd 获取了我的 ip 地址 2.在node js中,我这样编写了服务器监听代码
const hostname = "192.168.2.103";
const port = "3002";
app.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
现在应用程序将在此 IP 地址而不是本地主机上运行,因此我们可以在同一网络上的任何位置访问它,即使是在 从 API 进程中获取 React Native
关于android - 如何在 Android 设备上运行带有 Node js 后端的 React Native 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61122428/