Javascript 如何更改react js中的默认端口

Javascript 如何更改react js中的默认端口,javascript,node.js,reactjs,create-react-app,Javascript,Node.js,Reactjs,Create React App,我可以用默认端口3000启动react js。但是,当我将端口自定义为4200时,start:port=4200 react scripts start刚刚在package.json中更改,我无法启动react js应用程序 'PORT' is not recognized as an internal or external command, operable program or batch file. npm ERR! code ELIFECYCLE npm ERR! errno 1 np

我可以用默认端口3000启动react js。但是,当我将端口自定义为4200时,start:port=4200 react scripts start刚刚在package.json中更改,我无法启动react js应用程序

'PORT' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! todo-app@0.1.0 start: `PORT=4200 react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the todo-app@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional lo
ging output above.

npm ERR! A complete log of this run can be found in:

要在另一个端口上启动应用程序,请运行以下npm命令

npm启动-端口3002

或在包使用中进行配置

将start命令替换为以下命令

"start": "set PORT=3006 && react-scripts start"

另一个答案中没有提到的另一个选项是在根目录中创建一个.env文件,并将PORT=4200放入其中。它将自动加载到您的环境变量中

我猜你是在使用Windows-这就是在*nix中设置环境变量的语法。@manpret它工作了!!谢谢你的学习。Welcome它对我有用它对我有用。。。