简体   繁体   English

如何在 local.network 上部署 React + Express 应用程序?

[英]How to deploy a React + Express app on a local network?

This is my first post here, let me know if I do it wrong.这是我在这里的第一篇文章,如果我做错了请告诉我。 I would like to start by mentioning that I'm kind of a beginner developer.我想首先提到我是一名初级开发人员。 I've had a bunch of classes, but it's also my first time working on something of my own, from beginning to end (emphasis on "end").我上过很多课,但这也是我第一次从头到尾做自己的事情(强调“结束”)。

I'm working on a relatively simple app, for user management (CRUD, with different levels of authorizations) and shop management.我正在开发一个相对简单的应用程序,用于用户管理(CRUD,具有不同级别的授权)和商店管理。 I was given the choice of the tools, framework, language, etc, to use, with the only constraints that 1/ the main device to use it will be a tablet most of the times 2/ nothing should be hosted online.我可以选择要使用的工具、框架、语言等,唯一的限制是 1/ 使用它的主要设备大多数时候是平板电脑 2/ 不应在线托管任何内容。 I wanted to get more familiar with Javascript so I went with creating a React app (front) with Express Nodejs (back) and a MySQL database I access via Sequelize.我想更熟悉 Javascript,所以我开始使用 Express Nodejs(背面)创建一个 React 应用程序(正面)和一个通过 Sequelize 访问的 MySQL 数据库。

Development is going fine (for the most part thanks to many great posts here on SO), but I just got hit by the reality that I have never tried to build the app and see if it runs the way I intend.开发进展顺利(大部分归功于 SO 上的许多精彩帖子),但我刚刚被现实击中,因为我从未尝试构建应用程序并查看它是否按我预期的方式运行。 And I do not know how to do it.我不知道该怎么做。 I should have researched that earlier.我应该早点研究一下。

So far, in development I always tested everything on PC and phone by running npm start (front end) and node server.js (back end), and the client runs in a browser (when using a phone I access the IP adress and port, like 192.168.xx:3000).到目前为止,在开发过程中,我总是通过运行npm start (前端)和node server.js (后端)来测试 PC 和手机上的所有内容,客户端在浏览器中运行(当使用手机时,我访问 IP 地址和端口,例如 192.168.xx:3000)。 Backend listens to the 8080 port no prob, access to the MySQL database works as intended thanks to Sequelize.后端侦听 8080 端口没有问题,由于 Sequelize,对 MySQL 数据库的访问按预期工作。 Frontend listens to port 3000 to display the user interface on the browser, and React makes it easy to develop features in front, and quickly troubleshoot them. Frontend监听3000端口,将用户界面显示在浏览器上,React使得开发前端功能变得容易,并快速排查问题。 Everything works fine, and as expected, anyone in the same.network (and with a web browser) can access and use the app that way.一切正常,正如预期的那样,同一网络中的任何人(以及使用 web 浏览器)都可以通过这种方式访问和使用该应用程序。

This is the behavior I want to replicate with a production build: having a computer host the build, and run the "server" so that the app is available to any device in the local.network.这是我想用生产构建复制的行为:让一台计算机托管构建,并运行“服务器”,以便该应用程序可用于 local.network 中的任何设备。 So I guess I need to somehow make my build in a way to make it possible to turn on and off the "server" at will, maybe via a.exe?所以我想我需要以某种方式构建我的构建,以便可以随意打开和关闭“服务器”,也许是通过 a.exe? Or turn it on at the same time as the computer?还是和电脑同时开机?

I know I should have researched that earlier and not doing so was a mistake.我知道我应该早点研究,不这样做是错误的。 All I know is I'll have to use npm run build , to get the build folder, but I don't know what to do from there.我所知道的是我必须使用npm run build来获取构建文件夹,但我不知道从那里该做什么。 Could you help me figure it out?你能帮我弄清楚吗? Among many things I'm not sure of, is whether or not the host computer (not mine) needs to have node.js installed?在我不确定的许多事情中,主机(不是我的)是否需要安装 node.js? Does it also have to have MySQL installed?是否还必须安装 MySQL? Do I make a single build that incorporates the backend and the frontend, or do I build both separately?我是构建包含后端和前端的单个构建,还是分别构建两者? If so, how?如果是这样,如何?

Let me know if you need to see part of the code.如果您需要查看部分代码,请告诉我。 Thanks in advance and have a great day.提前致谢,祝你有美好的一天。

EDIT: App was created using create react app编辑:应用程序是使用create react app

There are options to deploy on cloud like Cloud Servers.有一些选项可以部署在像云服务器这样的云上。 But I think you're looking for hosting the application on the local machine.但我认为您正在寻找在本地计算机上托管应用程序的方法。 You need to create a service, bundle the application and serve whenever you want.您需要创建服务、捆绑应用程序并在需要时提供服务。

Following link might be helpful https://www.section.io/engineering-education/compile-your-nodejs-application-into-a-exe-file/以下链接可能会有所帮助https://www.section.io/engineering-education/compile-your-nodejs-application-into-a-exe-file/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在本地网络中部署在 ReactJS/NodeJS/Express/MongoDB 中创建的 Web 应用程序? - How to deploy web-app created in ReactJS/NodeJS/Express/MongoDB in a local network? 如何部署 vuejs - express 应用到本地 Ubuntu? - How to deploy vuejs - express app to local Ubuntu? 如何在 heroku 上使用 express 部署创建 React 应用程序? - how to deploy a create react app with express on heroku? 如何使用Webpack部署Express + React应用 - How to use webpack to deploy an Express + React app 如何将Express React App部署到AWS弹性豆杆上? - How to deploy express react app to aws elastic bean stalk? Express 应用程序无法在没有互联网的本地网络上运行 - Express app not working on local network without internet React 应用程序保持空白,Express 部署到 Heroku - React app stays blank with Express to deploy to Heroku 如何在本地网络中使用节点后端访问我的 React 应用程序? - How to access my React app with node backend in local network? 如何使用express和mongoose在本地网络中连接到MongoDB - How to connect to MongoDB in local network with express and mongoose 如何构建Nodejs应用程序并在没有Nodemon的本地LAN网络上部署 - How do I build a Nodejs App and deploy on a local LAN network with out Nodemon
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM