Unrecognized PORT command

前端 未结 7 1894
离开以前
离开以前 2021-02-14 04:22

In my localhost, running below command

PORT=4080 node server.js

But, it was throwing an unexpected error.

\'PORT\' is no

相关标签:
7条回答
  • 2021-02-14 05:03

    automatically run this port :3000,I tried windows working react

    "devDependencies": {
        "react-scripts": "0.8.4"
      },
      "scripts": {
        "start": "react-scripts start",
        "build": "react-scripts build",
        "test": "react-scripts test --env=jsdom",
        "eject": "react-scripts eject"
      }
    
    0 讨论(0)
  • 2021-02-14 05:08

    Here's a moronic way I found to recreate this problem:

    1. Create a npm based app on one system
    2. check it out on another system
    3. FAIL to run npm install
    4. run npm start

    Receive error described in question.

    0 讨论(0)
  • 2021-02-14 05:10

    Apart from cross-env, Below command can serve the purpose.

    SET PORT=4080 && node server.js 
    

    PS: Set environment variable for nodeJs, run command in project folder.

    0 讨论(0)
  • 2021-02-14 05:11

    In Windows you can set scripts in package.json:

    "start": " set PORT=portnumber && react-app-rewired start"
    

    or

    "start": " set PORT=3001 && react-script start".
    

    It worked for me:

    in package.json file

    0 讨论(0)
  • 2021-02-14 05:16

    SET PORT=8090 && nodemon server.js that worked for me

    0 讨论(0)
  • 2021-02-14 05:19

    You can try this way also

     "scripts": {
        "build": "concurrently \"cd client && npm build\" \"cd server && npm build\"",
        "install": "(cd client && npm) && (cd server && npm)",
        "start": "concurrently \"cd client && SET PORT=3000 && npm start\" \"cd server && SET PORT=3001 && npm start\"",
        "start:prod": "cd server && npm start:prod"
      }
    
    0 讨论(0)
提交回复
热议问题