简体   繁体   English

React.js:如何在不同端口上启动 React 应用程序

[英]React.js : How to start a react application on a different port

I just have started learning React.js and made two projects using Create React App .我刚刚开始学习React.js并使用Create React App制作了两个项目。

Now if I want to start both projects at the same time, I can't because both start on port 3000 by default.现在如果我想同时启动两个项目,我不能,因为默认情况下它们都在端口3000上启动。

Is there any way I can change the default port of one of them to something else like http://localhost:3001 and run them simultaneously?有什么办法可以将其中一个的默认端口更改为其他端口,例如 http://localhost:3001 并同时运行它们?

Note: I'm a Windows user注意:我是 Windows 用户

Modify start command from scripts section of package.json .package.jsonscripts部分修改start命令。

"start": “set PORT=3005 && react-scripts start"

There are couple of other ways also.还有其他几种方法。 Refer this link https://tech.amikelive.com/node-830/reactjs-changing-default-port-3000-in-create-react-app/请参阅此链接https://tech.amikelive.com/node-830/reactjs-changing-default-port-3000-in-create-react-app/

PS: You can specify the port number which you want. PS:你可以指定你想要的端口号。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM