简体   繁体   English

在WebStorm中配置端口 - React + Node Express应用程序

[英]Configure ports in WebStorm - React + Node Express app

I am going to do a fullstack implementation with WebStorm IDE. 我将使用WebStorm IDE进行fullstack实现。 I use react.js and node-express for this. 我为此使用react.js和node-express。 I can do this in separate projects. 我可以在单独的项目中做到这一点。 But I want to know how to implement both backend and frontend in WebStorm project while configuring ports. 但我想知道在配置端口时如何在WebStorm项目中实现后端和前端。

When starting the frontend we can give start html file in package.json file under "start": "parcel index.html" . 启动前端时,我们可以在"start": "parcel index.html"下的package.json文件中给出启动html文件。 When starting backend we can give "node app.js" But this can be done when we are doing the implementation in two different projects. 在启动后端时,我们可以给出"node app.js"但是当我们在两个不同的项目中执行时,可以这样做。

But if we are doing both frontend and backend how can I start react part and node-express part on two different ports? 但是,如果我们同时执行前端和后端,我如何才能在两个不同的端口上开始响应part和node-express部分? For example: 例如:
- react app > localhost:1234 - 反应应用> localhost:1234
- node-express > localhost:3000 - node-express> localhost:3000

"start": "parcel index.html"
"start": "node app.js"

// in package.json we can set only one start //在package.json中我们只能设置一个start

You can use a package like npm-run-all to achieve this. 您可以使用像npm-run-all这样的包来实现此目的。 Install it then have two separate scripts (like start-front-end and start-server) in your package.json that npm-run-all runs both of eg 安装它然后在package.json中有两个单独的脚本(如start-front-end和start-server),npm-run-all运行两个脚本,例如

"scripts": {
  "start-front-end": "parcel index.html --open",
  "start-server": "node app.js",
  "start": "npm-run-all start-server start-front-end",
}

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

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