Node.js/Express.js App Only Works on Port 3000

后端 未结 16 2204
暖寄归人
暖寄归人 2020-12-12 13:23

I have a Node.js/Express.js app running on my server that only works on port 3000 and I\'m trying to figure out why. Here\'s what I\'ve found:

  • Without specifyi
16条回答
  •  伪装坚强ぢ
    2020-12-12 14:04

    I think the best way is to use dotenv package and set the port on the .env config file without to modify the file www inside the folder bin.

    Just install the package with the command:

    npm install dotenv
    

    require it on your application:

    require('dotenv').config()
    

    Create a .env file in the root directory of your project, and add the port in it (for example) to listen on port 5000

    PORT=5000
    

    and that's it.

    More info here

提交回复
热议问题